Daniel Fütterer
13.12.20 07d2e3c26eced01875d5056d85f79b0d061a0d6f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
##### To Do #####
# - handle different keywords/types (what to process/ignore?)
# - recognize tags
# - sort by tags
# - scopes
 
import os
 
# a multidimensional list containing the Changelog
log = []
# a multidimensional list containing all commits separated by lines
commitHistory = []
# a list of keywords used in the default conventional git (https://www.conventionalcommits.org/en/v1.0.0/)
# may later get converted into a dict
keywords = ["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "style", "test"]
 
# get the formatted output from git log with additional delimiter for easier splitting
stream = os.popen("git log --format=%B%H----DELIMITER----")
output = stream.read()
output = output.split("----DELIMITER----")
del output[-1]
 
# compute every commit
for commit in output:
    # seperate lines
    wholeCommit = commit.split("\n")
    # delete empty strings
    commit = [x for x in wholeCommit if x]
    # delete long commit message
    if len(commit) == 3:
        del commit[1]
    # put commit into list
    commitHistory.append(commit)
    
    # handle commit types (work in progress)
    # variant a
    if commit[0].startswith("feat"):
        print("Feature recognized!")
    elif commit[0].startswith("chore"):
        print("Chore recognized!")
    # variant b
    for i in keywords:
        if commit[0].startswith(i):
            print(i)
 
 
 
# write into logfile for test purpose
with open("log.txt", "w") as file:
    for commit in commitHistory:
        for line in commit:
            file.write(line)
            file.write("\n")