From 2dbbcce517f7f1b691ff434a4957e96edd4cffac Mon Sep 17 00:00:00 2001 From: Thomas Woerner <twoerner@redhat.com> Date: Mon, 9 Nov 2020 12:41:01 +0100 Subject: [PATCH] Fix utils/changelog for merge commits without subject There is curently a merge commit without a subject, which leads into a traceback in the changelog script. The merge information provides the commit hash, which is now used to get the subject later on using the generated commits hash. --- utils/changelog | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/utils/changelog b/utils/changelog index 2e3e850d..2e5e5164 100755 --- a/utils/changelog +++ b/utils/changelog @@ -67,24 +67,40 @@ authors = {} lines = process.stdout.decode("utf-8").split("\n") +class Ref: + def __init__(self, commit): + self.commit = commit -def store(commits, prs, authors, commit, author, msg): + +def store(commits, prs, authors, commit, author, merge, msg): if commit is not None: if msg[0].startswith("Merge pull request #"): pr = int(msg[0].split()[3][1:]) - prs[pr] = msg[1].strip() + if len(msg) > 1: + prs[pr] = msg[1].strip() + else: + prs[pr] = Ref(merge) else: commits[commit] = msg[0].strip() authors.setdefault(author, []).append(commit) +def get_commit(commits, commit): + _commits = [value for key, value in commits.items() + if key.startswith(merge)] + if len(_commits) == 1: + return _commits[0] + return commit + + commit = None author = None +merge = None msg = None for line in lines: line = line.rstrip() if line.startswith("commit "): - store(commits, prs, authors, commit, author, msg) + store(commits, prs, authors, commit, author, merge, msg) author = None msg = [] commit = line[7:] @@ -95,13 +111,15 @@ for line in lines: key, value = line.split(":", 1) if key == "Author": author = value.split("<")[0].strip() - # Ignore Merge, Date, .. + elif key == "Merge": + merge = value.split()[1].strip() + # Ignore Date, .. except ValueError: pass # Add final commit if commit: - store(commits, prs, authors, commit, author, msg) + store(commits, prs, authors, commit, author, merge, msg) s = "Changes since %s" % version print("%s" % s) @@ -110,7 +128,11 @@ print() prs_sorted = sorted(prs.keys(), reverse=True) for pr in prs_sorted: - print(" - %s (#%d)" % (prs[pr], pr)) + if isinstance(prs[pr], Ref): + msg = get_commit(commits, prs[pr].commit) + else: + msg = prs[pr] + print(" - %s (#%d)" % (msg, pr)) print() s = "Detailed changelog since %s by author" % version -- GitLab