From 759948fffefb15b2119bd6e68a529f9daa7e41f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicki=20K=C5=99=C3=AD=C5=BEek?= Date: Tue, 13 Aug 2024 17:20:54 +0200 Subject: [PATCH 1/2] Sort changelog & relnotes entries by issue number To reduce the friction when handling the release notes, it is preferable to have the sections sorted by issue number, rather than merge order. Fallback to commit subject line if unavailable (e.g. for changelog entries). --- contrib/gitchangelog/gitchangelog.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/contrib/gitchangelog/gitchangelog.py b/contrib/gitchangelog/gitchangelog.py index c0d444baf1..b466c38c70 100755 --- a/contrib/gitchangelog/gitchangelog.py +++ b/contrib/gitchangelog/gitchangelog.py @@ -1802,6 +1802,13 @@ def versions_data_iter( ): continue + body = body_process(commit.body) + + ## Extract gitlab issue number + issue = None + if match := re.search(r".*:gl:`#([0-9]+)`", body): + issue = int(match.group(1)) + matched_section = first_matching(section_regexps, commit.subject) ## Finally storing the commit in the matching section @@ -1811,11 +1818,21 @@ def versions_data_iter( "author": commit.author_name, "authors": commit.author_names, "subject": subject_process(commit.subject), - "body": body_process(commit.body), + "body": body, "commit": commit, + "issue": issue, } ) + ## Sort sections by issue number or title + for section_key in sections.keys(): + sections[section_key].sort( + key=lambda c: ( + c["issue"] if c["issue"] is not None else sys.maxsize, + c["subject"], + ) + ) + ## Flush current version current_version["sections"] = [ {"label": k, "commits": sections[k]} for k in section_order if k in sections @@ -1830,7 +1847,7 @@ def changelog( unreleased_version_label="unreleased", include_commit_sha=False, warn=warn, ## Mostly used for test - **kwargs + **kwargs, ): """Returns a string containing the changelog of given repository From 993ba7cc7fb45d5b58c26ac95dc8e881477d10f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicki=20K=C5=99=C3=AD=C5=BEek?= Date: Tue, 13 Aug 2024 17:28:50 +0200 Subject: [PATCH 2/2] Omit MR link from release notes When manually handling the release notes (due to rst markup, fixups etc.), the different MR number for backports causes needless friction. Remove the reference from release notes and keep it only in changelog which isn't manually redacted. --- contrib/gitchangelog/relnotes.rc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/gitchangelog/relnotes.rc.py b/contrib/gitchangelog/relnotes.rc.py index 8430c7f70c..b2dae3a710 100644 --- a/contrib/gitchangelog/relnotes.rc.py +++ b/contrib/gitchangelog/relnotes.rc.py @@ -46,7 +46,7 @@ body_process = ( r" :gl:`\3`", ) | ReSub(r"\n*Merge branch '[^']+' into [^\n]+", r"") - | ReSub(r"\n*See merge request isc-projects/bind9(!\d+)", r" :gl:`\1`") + | ReSub(r"\n*See merge request isc-projects/bind9(!\d+)", r"") | Wrap(regexp="\n\n", separator="\n\n") | strip )