commit | author | age
|
c4d692
|
1 |
import os.path |
D |
2 |
import sys |
|
3 |
|
|
4 |
from functions import getCommitList |
|
5 |
from rawcommit import RawCommit |
|
6 |
from commit import Commit |
|
7 |
from scope import Scope |
|
8 |
from commitBody import CommitBody |
|
9 |
|
|
10 |
|
|
11 |
# Compute user input of repository path via console |
|
12 |
inputPath = input("Please enter the base path of the repository: ").strip() |
|
13 |
userDecision = input("Should the generated changelog be stored in another location (y/n)? ").lower().strip() |
|
14 |
if userDecision == "y": |
|
15 |
outputPath = input("Please enter the output path: ").strip() |
|
16 |
elif userDecision == "n": |
|
17 |
print("The changelog will be stored in the same location as the repository.") |
|
18 |
outputPath = inputPath |
|
19 |
else: |
|
20 |
print("invalid input") |
|
21 |
sys.exit(1) |
|
22 |
|
|
23 |
|
|
24 |
# create a list of separate commits in chronological order (new to old) |
|
25 |
commitHistory = getCommitList(inputPath) |
|
26 |
|
|
27 |
|
|
28 |
# Create a two-dimensional list by tags: [[tag, [commits]],[tag, [commits]],...] |
|
29 |
taggedHistory = [] |
|
30 |
for commit in commitHistory: |
|
31 |
if commit.tag.tagAsString: |
|
32 |
taggedHistory.append([commit.tag, commit]) |
|
33 |
else: |
|
34 |
if len(taggedHistory) == 0: |
|
35 |
taggedHistory.append([None, commit]) |
|
36 |
else: |
|
37 |
taggedHistory[-1].append(commit) |
|
38 |
|
|
39 |
|
|
40 |
# Construction of the changelog-file |
|
41 |
fileTemplate = ["# Changelog"] |
|
42 |
for tag in taggedHistory: |
|
43 |
## If latest commit has no tag: |
|
44 |
if not tag[0]: |
|
45 |
fileTemplate.append("\n## Without version number") |
|
46 |
else: |
|
47 |
fileTemplate.append("\n## Version " + tag[0].tagAsString) |
|
48 |
|
|
49 |
|
|
50 |
## Grouping by Type |
|
51 |
featType = ["Features"] |
|
52 |
fixType = ["Fixes"] |
|
53 |
otherType = ["Other"] |
|
54 |
nonconformCommits = [] |
|
55 |
|
|
56 |
for commit in tag[1:]: |
|
57 |
if commit.body.commitType == CommitBody.commitTypes[5]: # fix |
|
58 |
fixType.append(commit) |
|
59 |
elif commit.body.commitType == CommitBody.commitTypes[4]: # feat |
|
60 |
featType.append(commit) |
|
61 |
elif commit.body.commitType == "nonconform": |
|
62 |
nonconformCommits.append(commit) |
|
63 |
else: |
|
64 |
otherType.append(commit) |
|
65 |
|
|
66 |
## Sub-Grouping by Scopes within Types |
|
67 |
commitlistByType = [featType, fixType, otherType] |
|
68 |
for commitsByType in commitlistByType: |
|
69 |
if len(commitsByType) == 1: |
|
70 |
continue |
|
71 |
commitlistByScope = {} |
|
72 |
noScope = [] |
|
73 |
for commit in commitsByType: |
|
74 |
if type(commit) == str: |
|
75 |
continue |
|
76 |
if commit.body.scope == None: |
|
77 |
noScope.append(commit) |
|
78 |
elif commit.body.scope in commitlistByScope: |
|
79 |
commitlistByScope[commit.body.scope].append(commit) |
|
80 |
else: |
|
81 |
commitlistByScope[commit.body.scope] = [commit] |
|
82 |
|
|
83 |
fileTemplate.append("\n### " + commitsByType[0]) |
|
84 |
while len(commitlistByScope) > 0: |
|
85 |
scope, commits = commitlistByScope.popitem() |
|
86 |
fileTemplate.append("- *" + str(scope) + "*") |
|
87 |
for commit in commits: |
|
88 |
if commitsByType[0] == "Other": |
|
89 |
fileTemplate.append(" - (" + commit.body.commitType + ") " + commit.body.subject + commit.appendShortHash()) |
|
90 |
else: |
|
91 |
fileTemplate.append(" - " + commit.body.subject + commit.appendShortHash()) |
|
92 |
if len(noScope) > 0: |
|
93 |
fileTemplate.append("- *no scope*") |
|
94 |
for commit in noScope: |
|
95 |
fileTemplate.append(" - " + commit.body.subject + commit.appendShortHash()) |
|
96 |
|
|
97 |
## nonconform commits |
|
98 |
if len(nonconformCommits) > 0: |
|
99 |
fileTemplate.append("\n### Non-conform commits") |
|
100 |
for commit in nonconformCommits: |
|
101 |
fileTemplate.append("- " + commit.body.subject + commit.appendShortHash()) |
|
102 |
|
|
103 |
|
|
104 |
# write into changelog.md file |
|
105 |
with open(outputPath + "/changelog.md", "w") as file: |
|
106 |
for line in fileTemplate: |
|
107 |
file.write(line + "\n") |