TRX/tools/shared/changelog.py
2024-12-13 00:15:21 +01:00

37 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import re
from datetime import datetime
from pathlib import Path
def get_current_version_changelog(changelog_path: Path) -> str:
sections = [
section.strip()
for section in re.split("^##", changelog_path.read_text(), flags=re.M)
if re.search(r"- \w", section)
]
if sections:
section = sections[0]
return "\n".join(
line for line in section.splitlines() if not line.startswith("#")
)
def update_changelog_to_new_version(
changelog: str,
old_tag: str,
new_tag: str,
new_version_name: str,
stable_branch: str | None = "stable",
develop_branch: str = "develop",
) -> str:
if f"[{new_version_name}]" in changelog:
return changelog
today = datetime.now().strftime('%Y-%m-%d')
repo_url = 'https://github.com/LostArtefacts/TRX'
changelog = re.sub(r'^## \[Unreleased\].*\n*', '', changelog, flags=re.M)
changelog = (
f"## [Unreleased]({repo_url}/compare/{new_tag}...{develop_branch}) - ××××-××-××\n\n"
f"## [{new_version_name}]({repo_url}/compare/{old_tag}...{new_tag}) - {today}\n"
+ changelog
)
return changelog