From 0783221505775e18c583ee7f7ad914e5fd2aa8b9 Mon Sep 17 00:00:00 2001 From: Lukas K Date: Sat, 1 Oct 2022 17:12:52 +0200 Subject: [PATCH] add script for extracting changelog from commit messages --- scripts/generate_changelog.py | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 scripts/generate_changelog.py diff --git a/scripts/generate_changelog.py b/scripts/generate_changelog.py new file mode 100644 index 000000000..3485a262b --- /dev/null +++ b/scripts/generate_changelog.py @@ -0,0 +1,44 @@ +#!/usr/bin/python3 +import pygit2 +import sys +import re +from collections import defaultdict + +repo = pygit2.Repository(".") + +until = repo.revparse_single(f'refs/tags/{sys.argv[1]}').id + +walker = repo.walk(repo.head.target) +walker.simplify_first_parent() + +changelog_re = re.compile(r"changelog:\s+(.+?)/(.+?):\s+(.+?)(?:(?:\n\n)|$)", flags=re.DOTALL) + +lines = defaultdict(lambda: defaultdict(list)) + +def fix_spelling(word) : + if word in ("Enhacements", "Enhnacements") : + return "Enhancements" + return word.title() + +for commit in walker : + if commit.id == until : + break + #print(commit.message) + m = changelog_re.findall(commit.message.strip()) + for r in m : + cat, subcat, msg = r + msg = msg.replace("\n", " ") + line = f" - {msg} ({commit.id})" + lines[fix_spelling(cat)][fix_spelling(subcat)].append(line) + +for cat, subcats in lines.items() : + print("##", cat) + print() + for subcat, items in subcats.items() : + print("###", subcat) + print() + for item in items : + print(item) + print() + print() +