From f3c8d9c1a9bd16d58e65820f59eb1420b7610306 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Mon, 27 Oct 2025 10:56:52 +0100 Subject: [PATCH] Recognize an empty version section Fix the case when there are no pending changes in the top version section. This is not generally expected to happen, but it can happen when following the release process and there have not yet been any changes since the last release. Signed-off-by: Gilles Peskine --- scripts/assemble_changelog.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/assemble_changelog.py b/scripts/assemble_changelog.py index ef8c1e1fe..51ed27bd2 100755 --- a/scripts/assemble_changelog.py +++ b/scripts/assemble_changelog.py @@ -116,7 +116,7 @@ class TextChangelogFormat(ChangelogFormat): # Look for an incomplete release date return not re.search(r'[0-9x]{4}-[0-9x]{2}-[0-9x]?x', title) - _top_version_re = re.compile(r'(?:\A|\n)(=[^\n]*\n+)(.*?\n)(?:=|$)', + _top_version_re = re.compile(r'(?:\A|\n)(=[^\n]*\n)(.*?)(?:\n=|\Z)', re.DOTALL) _name_re = re.compile(r'=\s(.*)\s[0-9x]+\.', re.DOTALL) @classmethod @@ -126,7 +126,7 @@ class TextChangelogFormat(ChangelogFormat): top_version_start = m.start(1) top_version_end = m.end(2) top_version_title = m.group(1) - top_version_body = m.group(2) + top_version_body = m.group(2).strip('\n') + '\n' name = re.match(cls._name_re, top_version_title).group(1) if cls.is_released_version(top_version_title): top_version_end = top_version_start @@ -136,11 +136,12 @@ class TextChangelogFormat(ChangelogFormat): top_version_title, top_version_body, changelog_file_content[top_version_end:]) + _newlines_only_re = re.compile(r'\n*\Z') _category_title_re = re.compile(r'(^\w.*)\n+', re.MULTILINE) @classmethod def split_categories(cls, version_body): """A category title is a line with the title in column 0.""" - if not version_body: + if cls._newlines_only_re.match(version_body): return [] title_matches = list(re.finditer(cls._category_title_re, version_body)) if not title_matches or title_matches[0].start() != 0: