From 1f69ad4631ef12f60f8f54d060cd3656aececc27 Mon Sep 17 00:00:00 2001 From: df89 <df89@me.com> Date: Tue, 08 Jun 2021 12:04:13 +0200 Subject: [PATCH] feat: Input and output paths are now queried --- oop_changelog_scope.py | 61 ++++++++++++++++++------------ 1 files changed, 37 insertions(+), 24 deletions(-) diff --git a/oop_changelog_scope.py b/oop_changelog_scope.py index 69677c3..c385e12 100644 --- a/oop_changelog_scope.py +++ b/oop_changelog_scope.py @@ -1,9 +1,10 @@ import os.path +import sys ## To Do # - Breaking Changes # - Merge Commits -# - Error Handling +# - Deal with wrong user input (spelling, no repo) def getSeparatedGitLog(repo): try: @@ -58,7 +59,7 @@ def setScope(self): try: start = self.completeMessage.index("(")+1 - end = self.completeMessage.index(")") + end = self.completeMessage.index("):") except: self.scope = None else: @@ -134,10 +135,18 @@ #### Main #### -pathToRepo = "/Users/daniel/Developer/Repos/HfM/schumacher/Prisma-Binauralize" -#pathToRepo = "/Users/daniel/Desktop/testrepo" +inputPath = input("Please enter the base path of the repository: ") +userDecision = input("Should the generated changelog be stored in another location (y/n)? ").lower() +if userDecision == "y": + outputPath = (input("Please enter the output path: ")) +elif userDecision == "n": + print("The changelog will be stored in the same location as the repository.") + outputPath = inputPath +else: + print("invalid input") + sys.exit(1) -commitList = getSeparatedGitLog(pathToRepo) +commitList = getSeparatedGitLog(inputPath) # Create a list of commits commitHistory = [] @@ -167,40 +176,44 @@ # Grouping by Type - commitsByType = {"Other":[], "Fixes":[], "Features":[]} + featType = ["Features"] + fixType = ["Fixes"] + otherType = ["Other"] nonconformCommits = [] + for commit in tag[1:]: if commit.body.commitType == CommitBody.commitTypes[5]: # fix - commitsByType["Fixes"].append(commit) + fixType.append(commit) elif commit.body.commitType == CommitBody.commitTypes[4]: # feat - commitsByType["Features"].append(commit) + featType.append(commit) elif commit.body.commitType == "nonconform": nonconformCommits.append(commit) else: - commitsByType["Other"].append(commit) + otherType.append(commit) # Sub-Grouping by Scopes within Types - while len(commitsByType) > 0: - commitsByScope = {} - commitType, commits = commitsByType.popitem() - noScope = [] - if len(commits) == 0: + commitlistByType = [featType, fixType, otherType] + for commitsByType in commitlistByType: + if len(commitsByType) == 1: continue - - for commit in commits: + commitlistByScope = {} + noScope = [] + for commit in commitsByType: + if type(commit) == str: + continue if commit.body.scope == None: noScope.append(commit) - elif commit.body.scope in commitsByScope: - commitsByScope[commit.body.scope].append(commit) + elif commit.body.scope in commitlistByScope: + commitlistByScope[commit.body.scope].append(commit) else: - commitsByScope[commit.body.scope] = [commit] + commitlistByScope[commit.body.scope] = [commit] - fileTemplate.append("\n### " + str(commitType)) - while len(commitsByScope) > 0: - scope, commits = commitsByScope.popitem() + fileTemplate.append("\n### " + commitsByType[0]) + while len(commitlistByScope) > 0: + scope, commits = commitlistByScope.popitem() fileTemplate.append("- *" + str(scope) + "*") for commit in commits: - if commitType == "Other": + if commitsByType[0] == "Other": fileTemplate.append(" - (" + commit.body.commitType + ") " + commit.body.subject + commit.appendShortHash()) else: fileTemplate.append(" - " + commit.body.subject + commit.appendShortHash()) @@ -217,6 +230,6 @@ # write into changelog -with open(pathToRepo + "/changelog.md", "w") as file: +with open(outputPath + "/changelog.md", "w") as file: for line in fileTemplate: file.write(line + "\n") \ No newline at end of file -- Gitblit v1.9.1