Daniel Fütterer
28.01.21 398ff1150aa0334565b6aa614a08a910d238bfbc
feat: Scopes

scopes will be printed in bold
1 Dateien geändert
31 ■■■■ Geänderte Dateien
changelog_generator.py 31 ●●●● Patch | Ansicht | Raw | Blame | Historie
changelog_generator.py
@@ -3,7 +3,8 @@
##### To Do #####
# - handle further keywords/types other than "feat" and "fix"
# - scopes
# - deal with parameters configuring the output (dev/usr; types, hash y/n, ...)
# Refactoring: rewrite using oop (-> UML)
# the processing ang recognizing of the commit components should be improved
import os
@@ -71,20 +72,36 @@
    
    # Grouping by type "feat" and "fix"
    for commit in tag[1:]:
        if commit[0].startswith("fix: "):
            commitsByType["Fixes"].append(commit)
        elif commit[0].startswith("feat: "):
            commitsByType["Features"].append(commit)
        old = commit[0]
        if commit[0].startswith(keywords[5]): # "fix"
            if commit[0].startswith("fix: "):
                new = old[(old.index(":")+2):]
                commit[0] = new
                commitsByType["Fixes"].append(commit)
            else:
                new = "**" + old[(old.index("(")+1):old.index(")")] + "**: " + old[(old.index(":")+2):]
                commit[0] = new
                commitsByType["Fixes"].append(commit)
        elif commit[0].startswith(keywords[4]): # "feat"
            if commit[0].startswith("feat: "):
                new = old[(old.index(":")+2):]
                commit[0] = new
                commitsByType["Features"].append(commit)
            else:
                new = "**" + old[(old.index("(")+1):old.index(")")] + "**: " + old[(old.index(":")+2):]
                commit[0] = new
                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] + ")")
            fileTemplate.append("- " + feature[0] + " (" + commit[1][:6] + ")")
    if len(commitsByType["Fixes"]) != 0:
        fileTemplate.append("### Fixes")
        for fix in commitsByType["Fixes"]:
            fileTemplate.append("- " + fix[0][4:] + " (" + commit[1] + ")")
            fileTemplate.append("- " + fix[0] + " (" + commit[1][:6] + ")")
# write into changelog
with open("changelog.md", "w") as file: