From f8d69f225ca18c4bfc61af9c0037a6bbd3cc4875 Mon Sep 17 00:00:00 2001
From: Daniel Fütterer <df89@outlook.com>
Date: Sun, 24 Jan 2021 18:08:41 +0100
Subject: [PATCH] feat: Enable grouping of commits

---
 changelog_generator.py |   38 ++++++++++++++++++++++----------------
 1 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/changelog_generator.py b/changelog_generator.py
index 00d8d9f..039e05a 100644
--- a/changelog_generator.py
+++ b/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
 
@@ -41,18 +41,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
@@ -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:

--
Gitblit v1.9.1