Skip to content

Commit 4bdc113

Browse files
committed
Refactor release notes and commit message formatting for improved readability and maintainability
1 parent d03763e commit 4bdc113

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

src/utils/changelog.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,14 @@ def add_release_notes(release: GitRelease) -> str:
142142
This function returns a string containing the formatted release notes,
143143
including the release body and any additional information.
144144
"""
145+
release_body: str = (
146+
release.body.replace(f"{BLANK_LINE}", NEW_LINE)
147+
.replace("## ", "### ")
148+
.replace(NEW_LINE, f"{TAB * 2}")
149+
)
145150
return (
146151
f'{TAB}??? note "Release Notes"{BLANK_LINE}'
147-
f"{TAB * 2}{release.body.replace(f'{BLANK_LINE}', NEW_LINE).replace('## ', '### ').replace(NEW_LINE, f'{TAB * 2}')}{BLANK_LINE}"
152+
f"{TAB * 2}{release_body}{BLANK_LINE}"
148153
)
149154

150155

@@ -157,10 +162,13 @@ def add_commit_info(commit: Commit) -> str:
157162
# NOTE: We write the commit message to the output file.
158163
# We format the commit message to replace newlines with `{LINE_BREAK}` tags for better readability in Markdown.
159164
# We also include the author's login and a link to their GitHub profile, as well as a link to the commit itself.
165+
commit_message: str = commit.commit.message.replace(BLANK_LINE, NEW_LINE).replace(
166+
NEW_LINE, f"{LINE_BREAK}{NEW_LINE}{TAB * 3}"
167+
)
160168
return (
161-
f"{TAB * 2}* {commit.commit.message.replace(f'{NEW_LINE * 2}', NEW_LINE).replace(NEW_LINE, f'{LINE_BREAK}{NEW_LINE}{TAB * 3}')}"
169+
f"{TAB * 2}* {commit_message}"
162170
f" (by [{commit.author.login if commit.author else ''}]({commit.author.html_url if commit.author else ''}))"
163-
f" [View]({commit.html_url}){NEW_LINE * 2}"
171+
f" [View]({commit.html_url}){BLANK_LINE}"
164172
)
165173

166174

@@ -221,7 +229,7 @@ def main() -> None:
221229
f.write(add_release_notes(release))
222230

223231
### Add a section for updates ----
224-
f.write(f'{TAB}??? abstract "Updates"{NEW_LINE * 2}')
232+
f.write(f'{TAB}??? abstract "Updates"{BLANK_LINE}')
225233

226234
# NOTE: We fetch the commits between the current release and the previous release.
227235
# If the previous tag is "0", we fetch all commits until the current release.
@@ -259,4 +267,4 @@ def main() -> None:
259267
f.write(add_commit_info(commit))
260268

261269
### Add a newline after each release section ----
262-
f.write(f"{NEW_LINE * 2}")
270+
f.write(f"{BLANK_LINE}")

0 commit comments

Comments
 (0)