Daniel Fütterer
24.01.21 f8d69f225ca18c4bfc61af9c0037a6bbd3cc4875
feat: Enable grouping of commits

Commits belonging to a specific version release are grouped by type feat/fix
1 files modified
36 ■■■■■ changed files
changelog_generator.py 36 ●●●●● patch | view | raw | blame | history
changelog_generator.py
@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
##### To Do #####
# - handle different keywords/types (what to process/ignore?)
# - handle further keywords/types other than "feat" and "fix"
# - scopes
# the processing ang recognizing of the commit components should be improved
@@ -42,18 +42,6 @@
    # 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)
    #        pass
# Grouping History using tags
for commit in commitHistory:
@@ -72,14 +60,32 @@
# Construction of the changelog-file
fileTemplate = ["# Changelog"]
for tag in taggedHistory:
    # A Dictionairy to store grouped commits
    commitsByType = {"Fixes":[],"Features":[]}
    # If latest commit has no tag:
    if tag[0] == "":
        fileTemplate.append("\n## No version number yet ")
    else:
        fileTemplate.append("\n## Version " + tag[0])
    # Grouping by type "feat" and "fix"
    for commit in tag[1:]:
        fileTemplate.append("\t- " + commit[0] + " (" + commit[1] + ")")
        if commit[0].startswith("fix: "):
            commitsByType["Fixes"].append(commit)
        elif commit[0].startswith("feat: "):
            commitsByType["Features"].append(commit)
    # Creating grouped output
    if len(commitsByType["Features"]) != 0:
        fileTemplate.append("### Features")
        for feature in commitsByType["Features"]:
            fileTemplate.append("- " + feature[0][5:] + " (" + commit[1] + ")")
    if len(commitsByType["Fixes"]) != 0:
        fileTemplate.append("### Fixes")
        for fix in commitsByType["Fixes"]:
            fileTemplate.append("- " + fix[0][4:] + " (" + commit[1] + ")")
# write into changelog
with open("changelog.md", "w") as file:
    for line in fileTemplate: