2024-10-02 10:23:23 +02:00
|
|
|
|
import re
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_current_version_changelog(changelog_path: Path) -> str:
|
|
|
|
|
sections = [
|
2024-12-12 23:55:50 +01:00
|
|
|
|
section.strip()
|
|
|
|
|
for section in re.split("^##", changelog_path.read_text(), flags=re.M)
|
2024-10-02 10:23:23 +02:00
|
|
|
|
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
|
2024-10-03 12:59:00 +02:00
|
|
|
|
today = datetime.now().strftime('%Y-%m-%d')
|
|
|
|
|
repo_url = 'https://github.com/LostArtefacts/TRX'
|
|
|
|
|
changelog = re.sub(r'^## \[Unreleased\].*\n*', '', changelog, flags=re.M)
|
2024-10-02 10:23:23 +02:00
|
|
|
|
changelog = (
|
2024-10-03 12:59:00 +02:00
|
|
|
|
f"## [Unreleased]({repo_url}/compare/{new_tag}...{develop_branch}) - ××××-××-××\n\n"
|
|
|
|
|
f"## [{new_version_name}]({repo_url}/compare/{old_tag}...{new_tag}) - {today}\n"
|
2024-10-02 10:23:23 +02:00
|
|
|
|
+ changelog
|
|
|
|
|
)
|
|
|
|
|
return changelog
|