From ddffa10264e3ce16378924fec700b01bce145ba9 Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Tue, 21 Nov 2023 17:03:29 +0100 Subject: [PATCH 1/4] Initial changelog support for changelog assembling Add an initial changelog if no entries found un the changelog. Signed-off-by: Gabor Mezei --- scripts/assemble_changelog.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) mode change 100755 => 100644 scripts/assemble_changelog.py diff --git a/scripts/assemble_changelog.py b/scripts/assemble_changelog.py old mode 100755 new mode 100644 index d5f705c1c..afff200ee --- a/scripts/assemble_changelog.py +++ b/scripts/assemble_changelog.py @@ -127,10 +127,17 @@ class TextChangelogFormat(ChangelogFormat): def extract_top_version(cls, changelog_file_content): """A version section starts with a line starting with '='.""" m = re.search(cls._top_version_re, changelog_file_content) - top_version_start = m.start(1) - top_version_end = m.end(2) - top_version_title = m.group(1) - top_version_body = m.group(2) + if m: + top_version_start = m.start(1) + top_version_end = m.end(2) + top_version_title = m.group(1) + top_version_body = m.group(2) + # No entries found + else: + top_version_start = None + top_version_end = None + top_version_title = '' + top_version_body = '' if cls.is_released_version(top_version_title): top_version_end = top_version_start top_version_title = cls._unreleased_version_text + '\n\n' @@ -244,7 +251,11 @@ class ChangeLog: self.categories = OrderedDict() for category in STANDARD_CATEGORIES: self.categories[category] = '' - offset = (self.header + self.top_version_title).count('\n') + 1 + if self.header: + offset = (self.header + self.top_version_title).count('\n') + 1 + else: + offset = 0 + self.add_categories_from_text(input_stream.name, offset, top_version_body, True) @@ -258,8 +269,10 @@ class ChangeLog: """Write the changelog to the specified file. """ with open(filename, 'w', encoding='utf-8') as out: - out.write(self.header) - out.write(self.top_version_title) + if self.header: + out.write(self.header) + if self.top_version_title: + out.write(self.top_version_title) for title, body in self.categories.items(): if not body: continue From 8933c04e44b35afb2fa7ecf75c9791e1892b8981 Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Tue, 21 Nov 2023 17:05:43 +0100 Subject: [PATCH 2/4] Enable to specify the name of the project in the changelog The name read out from the previous entry. Signed-off-by: Gabor Mezei --- scripts/assemble_changelog.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) mode change 100644 => 100755 scripts/assemble_changelog.py diff --git a/scripts/assemble_changelog.py b/scripts/assemble_changelog.py old mode 100644 new mode 100755 index afff200ee..81ce68223 --- a/scripts/assemble_changelog.py +++ b/scripts/assemble_changelog.py @@ -115,7 +115,7 @@ class ChangelogFormat: class TextChangelogFormat(ChangelogFormat): """The traditional Mbed TLS changelog format.""" - _unreleased_version_text = '= Mbed TLS x.x.x branch released xxxx-xx-xx' + _unreleased_version_text = '= {} x.x.x branch released xxxx-xx-xx' @classmethod def is_released_version(cls, title): # Look for an incomplete release date @@ -123,6 +123,7 @@ class TextChangelogFormat(ChangelogFormat): _top_version_re = re.compile(r'(?:\A|\n)(=[^\n]*\n+)(.*?\n)(?:=|$)', re.DOTALL) + _name_re = re.compile(r'=\s(.*)\s[0-9x]+\.', re.DOTALL) @classmethod def extract_top_version(cls, changelog_file_content): """A version section starts with a line starting with '='.""" @@ -132,15 +133,17 @@ class TextChangelogFormat(ChangelogFormat): top_version_end = m.end(2) top_version_title = m.group(1) top_version_body = m.group(2) + name = re.match(cls._name_re, top_version_title).group(1) # No entries found else: top_version_start = None top_version_end = None + name = 'xxx' top_version_title = '' top_version_body = '' if cls.is_released_version(top_version_title): top_version_end = top_version_start - top_version_title = cls._unreleased_version_text + '\n\n' + top_version_title = cls._unreleased_version_text.format(name) + '\n\n' top_version_body = '' return (changelog_file_content[:top_version_start], top_version_title, top_version_body, From 4e574dbd437179571b38c0d96be9c7f9f9132c0f Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Wed, 22 Nov 2023 17:48:00 +0100 Subject: [PATCH 3/4] Remove initial changelog entry creation support Signed-off-by: Gabor Mezei --- scripts/assemble_changelog.py | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/scripts/assemble_changelog.py b/scripts/assemble_changelog.py index 81ce68223..b2fa96a07 100755 --- a/scripts/assemble_changelog.py +++ b/scripts/assemble_changelog.py @@ -128,19 +128,11 @@ class TextChangelogFormat(ChangelogFormat): def extract_top_version(cls, changelog_file_content): """A version section starts with a line starting with '='.""" m = re.search(cls._top_version_re, changelog_file_content) - if m: - top_version_start = m.start(1) - top_version_end = m.end(2) - top_version_title = m.group(1) - top_version_body = m.group(2) - name = re.match(cls._name_re, top_version_title).group(1) - # No entries found - else: - top_version_start = None - top_version_end = None - name = 'xxx' - top_version_title = '' - top_version_body = '' + top_version_start = m.start(1) + top_version_end = m.end(2) + top_version_title = m.group(1) + top_version_body = m.group(2) + 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 top_version_title = cls._unreleased_version_text.format(name) + '\n\n' @@ -272,10 +264,8 @@ class ChangeLog: """Write the changelog to the specified file. """ with open(filename, 'w', encoding='utf-8') as out: - if self.header: - out.write(self.header) - if self.top_version_title: - out.write(self.top_version_title) + out.write(self.header) + out.write(self.top_version_title) for title, body in self.categories.items(): if not body: continue From fe23daf8a3c0186f941068011761e34bd1ab7c99 Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Mon, 4 Dec 2023 14:37:31 +0100 Subject: [PATCH 4/4] Remove leftover code from initial changelog support Signed-off-by: Gabor Mezei --- scripts/assemble_changelog.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/assemble_changelog.py b/scripts/assemble_changelog.py index b2fa96a07..07e6fc58a 100755 --- a/scripts/assemble_changelog.py +++ b/scripts/assemble_changelog.py @@ -246,10 +246,7 @@ class ChangeLog: self.categories = OrderedDict() for category in STANDARD_CATEGORIES: self.categories[category] = '' - if self.header: - offset = (self.header + self.top_version_title).count('\n') + 1 - else: - offset = 0 + offset = (self.header + self.top_version_title).count('\n') + 1 self.add_categories_from_text(input_stream.name, offset, top_version_body, True)