diff options
author | Robert Adam <dev@robert-adam.de> | 2021-03-20 21:14:39 +0300 |
---|---|---|
committer | Robert Adam <dev@robert-adam.de> | 2021-03-20 21:14:39 +0300 |
commit | 7159d5e885535b7cbbcc86077ed238af842d2494 (patch) | |
tree | 4154c99064d205cafaec2aafad9ef9f7ea727c50 /scripts | |
parent | 192b3b936821289feb97b3fa0d7d6de0e74079a3 (diff) |
MAINT: Make changelog script more robust
The assumptions about the format of the merge commit message were rather
strict and thus slight deviations would cause the script to fail.
Therefore the script got overhauled and is now using a (hopefully) more
versatile RegEx to do the job.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/generateChangelog.py | 37 |
1 files changed, 10 insertions, 27 deletions
diff --git a/scripts/generateChangelog.py b/scripts/generateChangelog.py index f6cf1c03c..af2576c33 100755 --- a/scripts/generateChangelog.py +++ b/scripts/generateChangelog.py @@ -8,6 +8,7 @@ import argparse import platform import subprocess +import re from commitMessage.CommitMessage import CommitMessage, CommitFormatError @@ -19,19 +20,6 @@ def cmd(args): raise Exception('cmd(): {0} failed with status {1}: {2}'.format(args, p.returncode, stderr)) return stdout.decode('utf-8') -def isRelevantCommit(commitLine): - if commitLine.strip() == "": - return False - - components = commitLine.split() - - if len(components) < 2: - return False - - # First component is commit hash - # We only consider merge commits to be relevant - return components[1].lower() == "merge" - def formatChangeLine(line, prNumber, target): if target == "github": return "- {} (#{})".format(line, prNumber) @@ -49,8 +37,9 @@ def main(): default="other") args = parser.parse_args() + mergeCommitPattern = re.compile("^([0-9a-f]+)\s*[Mm]erge\s.+?#(\d+):?\s*(.+)$", re.MULTILINE) + commits = cmd(["git", "log" ,"--format=oneline", "--date=short", "{}..{}".format(args.FROM_TAG, args.TO_TAG)]).split("\n") - commits = list(filter(isRelevantCommit, commits)) serverChanges = [] clientChanges = [] @@ -60,21 +49,15 @@ def main(): skipTypes = set(["FORMAT", "DOCS", "TEST", "MAINT", "CI", "REFAC", "BUILD", "TRANSLATION"]) for commitLine in commits: - parts = commitLine.split(maxsplit=1) - commitHash = parts[0] - commitTitle = parts[1] - - assert ":" in commitTitle - assert "#" in commitTitle + match = re.match(mergeCommitPattern, commitLine) - prTagStart = commitTitle.find("#") - prTagEnd = commitTitle.find(":") - assert prTagStart + 1 < prTagEnd + if not match: + # Commit doesn't match the expected pattern and is thus ignored + continue - # Extract PR number - prNumber = commitTitle[prTagStart + 1 : prTagEnd] - # Cut out PR information from commit title - commitTitle = commitTitle[prTagEnd + 1 : ].strip() + commitHash = match.group(1) + prNumber = match.group(2) + commitTitle = match.group(3) try: commit = CommitMessage(commitTitle) |