From 07d2e3c26eced01875d5056d85f79b0d061a0d6f Mon Sep 17 00:00:00 2001
From: Daniel Fütterer <df89@outlook.com>
Date: Sun, 13 Dec 2020 14:08:13 +0100
Subject: [PATCH] feat: Added Python script

---
 changelog_generator.py |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/changelog_generator.py b/changelog_generator.py
new file mode 100644
index 0000000..d9cc906
--- /dev/null
+++ b/changelog_generator.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+##### To Do #####
+# - handle different keywords/types (what to process/ignore?)
+# - recognize tags
+# - sort by tags
+# - scopes
+
+import os
+
+# a multidimensional list containing the Changelog
+log = []
+# a multidimensional list containing all commits separated by lines
+commitHistory = []
+# a list of keywords used in the default conventional git (https://www.conventionalcommits.org/en/v1.0.0/)
+# may later get converted into a dict
+keywords = ["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "style", "test"]
+
+# get the formatted output from git log with additional delimiter for easier splitting
+stream = os.popen("git log --format=%B%H----DELIMITER----")
+output = stream.read()
+output = output.split("----DELIMITER----")
+del output[-1]
+
+# compute every commit
+for commit in output:
+    # seperate lines
+    wholeCommit = commit.split("\n")
+    # delete empty strings
+    commit = [x for x in wholeCommit if x]
+    # delete long commit message
+    if len(commit) == 3:
+        del commit[1]
+    # 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)
+
+
+
+# write into logfile for test purpose
+with open("log.txt", "w") as file:
+    for commit in commitHistory:
+        for line in commit:
+            file.write(line)
+            file.write("\n")

--
Gitblit v1.9.1