From 398ff1150aa0334565b6aa614a08a910d238bfbc Mon Sep 17 00:00:00 2001
From: Daniel Fütterer <df89@outlook.com>
Date: Thu, 28 Jan 2021 11:54:08 +0100
Subject: [PATCH] feat: Scopes

---
 changelog_generator.py |   31 ++++++++++++++++++++++++-------
 1 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/changelog_generator.py b/changelog_generator.py
index 039e05a..087dcf5 100644
--- a/changelog_generator.py
+++ b/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:

--
Gitblit v1.9.1