continuwuity/bin/linkify-changelog.py
Jade Ellis fa0a11ba4f
Some checks failed
Documentation / Build and Deploy Documentation (push) Has been cancelled
Checks / Prek / Pre-commit & Formatting (push) Has been cancelled
Checks / Prek / Check changed files (push) Has been cancelled
Checks / Prek / Clippy and Cargo Tests (push) Has been cancelled
Release Docker Image / Build linux-amd64 (release) (push) Has been cancelled
Release Docker Image / Build linux-arm64 (release) (push) Has been cancelled
Release Docker Image / Create Multi-arch Release Manifest (push) Has been cancelled
Release Docker Image / Build linux-amd64 (max-perf) (push) Has been cancelled
Release Docker Image / Build linux-arm64 (max-perf) (push) Has been cancelled
Release Docker Image / Create Max-Perf Manifest (push) Has been cancelled
Release Docker Image / Release Binaries (push) Has been cancelled
Release Docker Image / Mirror Images (push) Has been cancelled
chore: Update release process
2026-08-22 22:06:32 +01:00

55 lines
1.4 KiB
Python
Executable file

#!/usr/bin/env python3
"""
Nexy's magic changelog linkifier script! Linkify that changelog! Make it clickable!
The masses LOVE being able to click things!
Usage:
python3 bin/linkify-changelog.py
Assumes CHANGELOG.md is in the current directory.
Will not write if subsequent calls to linkify would change the output (to avoid nested linkification).
"""
import os
import re
import shutil
def linkify(text: str) -> str:
# ARCANE REGEX RUNES I CALL UPON THEE TO LINKIFY MY SHIT! GO!
# Linkify issues and PRs
reformatted = re.sub(
r"\(#(\d{4})\)",
r"([#\1](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/\1))",
text
)
# Linkify MSCs
reformatted = re.sub(
r"([^\[])(MSC(\d{4}))([^\]])",
r"\1[\2](https://github.com/matrix-org/matrix-spec-proposals/pull/\3)\4",
reformatted
)
return reformatted
def main():
with open("CHANGELOG.md") as fd:
changelog = fd.read()
linkified = linkify(changelog)
# verify that double-writes are idempotent
linkified2 = linkify(linkified)
assert linkified == linkified2, "Double-linkification was not idempotent!"
try:
os.mkdir("out")
except FileExistsError:
pass
shutil.copy("CHANGELOG.md", "out" + os.sep + "CHANGELOG.md.old")
with open("CHANGELOG.md", "w") as fd:
fd.write(linkified)
if __name__ == "__main__":
main()