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 |
# - scopes |
a6a9a0
|
7 |
# the processing ang recognizing of the commit components should be improved |
07d2e3
|
8 |
|
DF |
9 |
import os |
|
10 |
|
|
11 |
# a multidimensional list containing all commits separated by lines |
|
12 |
commitHistory = [] |
a6a9a0
|
13 |
# a multidimensional list containing all commits grouped by tags |
DF |
14 |
taggedHistory = [] |
07d2e3
|
15 |
# a list of keywords used in the default conventional git (https://www.conventionalcommits.org/en/v1.0.0/) |
DF |
16 |
# may later get converted into a dict |
|
17 |
keywords = ["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "style", "test"] |
|
18 |
|
|
19 |
# get the formatted output from git log with additional delimiter for easier splitting |
a6a9a0
|
20 |
stream = os.popen("git log --format=%B%H%n%d%n--END--") |
07d2e3
|
21 |
output = stream.read() |
a6a9a0
|
22 |
output = output.split("--END--") |
07d2e3
|
23 |
del output[-1] |
DF |
24 |
|
a6a9a0
|
25 |
# compute every commit (sepratae, delete unnecessary components, store into commitHistory) |
07d2e3
|
26 |
for commit in output: |
DF |
27 |
# seperate lines |
|
28 |
wholeCommit = commit.split("\n") |
|
29 |
commit = [x for x in wholeCommit if x] |
a6a9a0
|
30 |
|
DF |
31 |
# delete unnecessary lines |
|
32 |
for i,line in enumerate(commit): |
|
33 |
if line == "": |
|
34 |
del commit[i] |
|
35 |
|
|
36 |
if len(commit[1]) == 40: # Please improve here |
|
37 |
pass |
|
38 |
elif len(commit[2]) == 40: |
07d2e3
|
39 |
del commit[1] |
a6a9a0
|
40 |
else: commit[2] = commit[2].strip() |
DF |
41 |
|
07d2e3
|
42 |
# put commit into list |
DF |
43 |
commitHistory.append(commit) |
|
44 |
|
|
45 |
# handle commit types (work in progress) |
|
46 |
# variant a |
a6a9a0
|
47 |
#if commit[0].startswith("feat"): |
DF |
48 |
# print("Feature recognized!") |
|
49 |
#elif commit[0].startswith("chore"): |
|
50 |
# print("Chore recognized!") |
07d2e3
|
51 |
# variant b |
a6a9a0
|
52 |
#for i in keywords: |
DF |
53 |
# if commit[0].startswith(i): |
|
54 |
# print(i) |
|
55 |
# pass |
07d2e3
|
56 |
|
DF |
57 |
|
a6a9a0
|
58 |
# Grouping History using tags |
1092d6
|
59 |
for commit in commitHistory: |
a6a9a0
|
60 |
# Look if commit has a tag |
DF |
61 |
if (len(commit) == 3) and ("tag: v" in commit[2]): |
|
62 |
taggedHistory.append([commit[2][(commit[2].rfind(": v")+3):-1],commit[0:2]]) |
|
63 |
else: |
1092d6
|
64 |
# Check if latest commit has a tag |
DF |
65 |
if len(taggedHistory)==0: |
|
66 |
# If there is no tag, create empty string instead |
|
67 |
taggedHistory.append(["", commit]) |
|
68 |
else: |
|
69 |
taggedHistory[-1].append(commit) |
07d2e3
|
70 |
|
a6a9a0
|
71 |
|
DF |
72 |
# Construction of the changelog-file |
|
73 |
fileTemplate = ["# Changelog"] |
|
74 |
for tag in taggedHistory: |
1092d6
|
75 |
if tag[0] == "": |
DF |
76 |
fileTemplate.append("\n## No version number yet ") |
|
77 |
else: |
|
78 |
fileTemplate.append("\n## Version " + tag[0]) |
|
79 |
|
|
80 |
|
a6a9a0
|
81 |
for commit in tag[1:]: |
DF |
82 |
fileTemplate.append("\t- " + commit[0] + " (" + commit[1] + ")") |
|
83 |
# write into changelog |
|
84 |
with open("changelog.md", "w") as file: |
|
85 |
for line in fileTemplate: |
|
86 |
file.write(line + "\n") |