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