| | |
| | | import os.path |
| | | |
| | | ## To Do |
| | | # - Breaking Changes |
| | | # - Merge Commits |
| | | # - Error Handling |
| | | |
| | | def getSeparatedGitLog(repo): |
| | | try: |
| | | stream = os.popen("git -C {} log --format=%B--SEP--%H--SEP--%d--END--".format(repo)) |
| | |
| | | self.setCommitType() |
| | | |
| | | def setSubjectAndBody(self): |
| | | subStart = self.completeMessage.index(": ")+2 |
| | | try: |
| | | subStart = self.completeMessage.index(": ")+2 |
| | | except: |
| | | try: |
| | | subStart = self.completeMessage.index("\n") |
| | | except: |
| | | subStart = 0 |
| | | try: |
| | | subEnd = self.completeMessage.index("\n") |
| | | except: |
| | |
| | | if (self.completeMessage.startswith((commitType + ": "))) or (self.completeMessage.startswith((commitType + "("))): |
| | | self.commitType = commitType |
| | | break |
| | | else: |
| | | self.commitType = "nonconform" |
| | | |
| | | def getCommitMessageWithType(self): |
| | | return self.commitType + ": " + self.subject |
| | | |
| | | |
| | | class CommitTag: |
| | |
| | | self.body = CommitBody(rawCommit.body) |
| | | self.tag = CommitTag(rawCommit.tag) |
| | | self.hash = rawCommit.hash |
| | | |
| | | def appendShortHash(self): |
| | | return " (" + self.hash[:6] + ")" |
| | | |
| | | |
| | | |
| | |
| | | fileTemplate = ["# Changelog"] |
| | | for tag in taggedHistory: |
| | | # A Dictionairy to store grouped commits |
| | | commitsByType = {"Fixes":[], "Features":[], "Other":[]} |
| | | commitsByType = {"Fixes":[], "Features":[], "Other":[], "Nonconform":[]} |
| | | commitsByScope = {} |
| | | |
| | | # If latest commit has no tag: |
| | |
| | | else: |
| | | commitsByScope[commit.body.scope].append(commit) |
| | | for scope in commitsByScope: |
| | | fileTemplate.append("\n### Scope: " + scope) |
| | | fileTemplate.append("### Scope: " + scope) |
| | | for commit in commitsByScope[scope]: |
| | | fileTemplate.append("\n- " + commit.body.commitType + ": " + commit.body.subject + " (" + commit.hash[:6] + ")") |
| | | fileTemplate.append("- " + commit.body.getCommitMessageWithType() + commit.appendShortHash()) |
| | | 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) |
| | | |
| | | if len(commitsByType["Features"]) != 0: |
| | | fileTemplate.append("### Features") |
| | | for feature in commitsByType["Features"]: |
| | | fileTemplate.append("- " + feature.body.subject + " (" + feature.hash[:6] + ")") |
| | | fileTemplate.append("- " + feature.body.subject + feature.appendShortHash()) |
| | | if len(commitsByType["Fixes"]) != 0: |
| | | fileTemplate.append("### Fixes") |
| | | for fix in commitsByType["Fixes"]: |
| | | fileTemplate.append("- " + fix.body.subject + " (" + fix.hash[:6] + ")") |
| | | fileTemplate.append("- " + fix.body.subject + fix.appendShortHash()) |
| | | if len(commitsByType["Other"]) != 0: |
| | | fileTemplate.append("### Other") |
| | | for other in commitsByType["Other"]: |
| | | fileTemplate.append("\n- " + other.body.commitType + ": " + other.body.subject + " (" + other.hash[:6] + ")") |
| | | 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 |