From b07d2e00d40692f9076e65cfe41140d4515b7b32 Mon Sep 17 00:00:00 2001
From: Daniel Fütterer <df89@outlook.com>
Date: Tue, 27 Apr 2021 14:12:29 +0200
Subject: [PATCH] feat: Added version with scopes

---
 oop_changelog.py |   65 ++++++++++++++++----------------
 1 files changed, 32 insertions(+), 33 deletions(-)

diff --git a/oop_changelog.py b/oop_changelog.py
index 4b0b8b6..fe19006 100644
--- a/oop_changelog.py
+++ b/oop_changelog.py
@@ -66,7 +66,7 @@
     
     def setCommitType(self):
         for commitType in self.commitTypes:
-            if (self.completeMessage.startswith((commitType + ": "))) or (self.completeMessage.startswith((commitType + "("))):
+            if (self.completeMessage.startswith((commitType + ": "))) or (self.completeMessage.startswith((commitType + "("))) or (self.completeMessage.startswith((commitType + " ("))):
                 self.commitType = commitType
                 break
             else:
@@ -127,7 +127,10 @@
 
 #### Main ####
 
-commitList = getSeparatedGitLog("/Users/daniel/Desktop/testrepo")
+pathToRepo = "/Users/daniel/Developer/Repos/HfM/schumacher/Prisma-Binauralize"
+#pathToRepo = "/Users/daniel/Desktop/testrepo"
+
+commitList = getSeparatedGitLog(pathToRepo)
 
 # Create a list of commits
 commitHistory = []
@@ -150,57 +153,53 @@
 fileTemplate = ["# Changelog"]
 for tag in taggedHistory:
     # A Dictionairy to store grouped commits
-    commitsByType = {"Fixes":[], "Features":[], "Other":[], "Nonconform":[]}
-    commitsByScope = {}
+    commitsByType = {"fix":[], "feat":[], "Other":[], "Nonconform":[]}
 
     # If latest commit has no tag:
     if not tag[0]:
-        fileTemplate.append("\n## No version number yet ")
+        fileTemplate.append("\n## No version number yet")
     else:
         fileTemplate.append("\n## Version " + tag[0].tagAsString)
 
     # Grouping by CommitTypes
     for commit in tag[1:]:
-        # Dealing with scopes
-        if commit.body.scope:
-            if commit.body.scope not in commitsByScope:
-                commitsByScope[commit.body.scope] = [commit]
-            else:
-                commitsByScope[commit.body.scope].append(commit)
-            for scope in commitsByScope:
-                fileTemplate.append("### Scope: " + scope)
-                for commit in commitsByScope[scope]:
-                    fileTemplate.append("- " + commit.body.getCommitMessageWithType() + commit.appendShortHash())
+        if commit.body.commitType == CommitBody.commitTypes[5]: # fix
+            commitsByType["fix"].append(commit)
+        elif commit.body.commitType == CommitBody.commitTypes[4]: # feat
+            commitsByType["feat"].append(commit)
+        elif commit.body.commitType == "nonconform":
+            commitsByType["Nonconform"].append(commit)
         else:
-            # Sorting in predifend groups
-            if commit.body.commitType == CommitBody.commitTypes[5]: # fix
-                commitsByType["Fixes"].append(commit)
-            elif commit.body.commitType == CommitBody.commitTypes[4]: # feat
-                commitsByType["Features"].append(commit)
-            elif commit.body.commitType == "nonconform":
-                commitsByType["Nonconform"].append(commit)
-            else:
-                commitsByType["Other"].append(commit)
+            commitsByType["Other"].append(commit)
     
-    if len(commitsByType["Features"]) != 0:
+    if len(commitsByType["feat"]) != 0:
         fileTemplate.append("### Features")
-        for feature in commitsByType["Features"]:
-            fileTemplate.append("- " + feature.body.subject + feature.appendShortHash())
-    if len(commitsByType["Fixes"]) != 0:
+        for feature in commitsByType["feat"]:
+            if feature.body.scope:
+                fileTemplate.append("- **" + feature.body.scope + "**: " + feature.body.subject + feature.appendShortHash())
+            else:
+                fileTemplate.append("- " + feature.body.subject + feature.appendShortHash())
+    if len(commitsByType["fix"]) != 0:
         fileTemplate.append("### Fixes")
-        for fix in commitsByType["Fixes"]:
-            fileTemplate.append("- " + fix.body.subject + fix.appendShortHash())
+        for fix in commitsByType["fix"]:
+            if fix.body.scope:
+                fileTemplate.append("- **" + fix.body.scope  + "**: " + fix.body.scope + fix.appendShortHash())
+            else:
+                fileTemplate.append("- " + fix.body.subject + fix.appendShortHash())
     if len(commitsByType["Other"]) != 0:
         fileTemplate.append("### Other")
         for other in commitsByType["Other"]:
-            fileTemplate.append("- " + other.body.getCommitMessageWithType() + other.appendShortHash())
+            if other.body.scope:
+                fileTemplate.append("- **" + other.body.scope + "**: " +  other.body.getCommitMessageWithType() + other.appendShortHash())
+            else:
+                fileTemplate.append("- " + other.body.getCommitMessageWithType() + other.appendShortHash())
     if len(commitsByType["Nonconform"]) != 0:
         fileTemplate.append("### Non-conventional")
         for nonconform in commitsByType["Nonconform"]:
             fileTemplate.append("- " + nonconform.body.subject + nonconform.appendShortHash())
-        
+
 
 # write into changelog
-with open("changelog.md", "w") as file:
+with open(pathToRepo + "/changelog.md", "w") as file:
     for line in fileTemplate:
         file.write(line + "\n")
\ No newline at end of file

--
Gitblit v1.9.1