117 lines
3.7 KiB
Python
117 lines
3.7 KiB
Python
#!/usr/bin/env python3
|
|||
|
|
"""release_notes.py — Génère les release notes Forgejo depuis le dernier tag du même préfixe.
|
||
|
|
|
||
|
|
Usage:
|
||
|
|
release_notes.py [TAG] [PREFIX] [REPO_URL]
|
||
|
|
|
||
|
|
TAG : tag de la release courante (défaut : détecté via git describe)
|
||
|
|
PREFIX : préfixe de tag (défaut : 'v') — les notes ne comparent qu'avec
|
||
|
|
les tags du même préfixe (ex. 'agent-v' pour l'agent)
|
||
|
|
REPO_URL : base d'URL du repo pour les liens commits (défaut : forgejo.tordais.cc)
|
||
|
|
|
||
|
|
Sortie : markdown prêt pour le body d'une release Forgejo (stdout).
|
||
|
|
"""
|
||
|
|
import subprocess
|
||
|
|
import sys
|
||
|
|
import datetime
|
||
|
|
|
||
|
|
CATEGORIES = {
|
||
|
|
"feat": ("✨ Features", "feature"),
|
||
|
|
"fix": ("🐛 Fixes", "bug"),
|
||
|
|
"perf": ("⚡ Performance", "perf"),
|
||
|
|
"chore": ("🧹 Maintenance", "chore"),
|
||
|
|
"refactor": ("🧹 Maintenance", "refactor"),
|
||
|
|
"docs": ("🧹 Maintenance", "docs"),
|
||
|
|
"style": ("🧹 Maintenance", "style"),
|
||
|
|
"build": ("🧹 Maintenance", "build"),
|
||
|
|
"ci": ("🧹 Maintenance", "ci"),
|
||
|
|
"test": ("🧹 Maintenance", "test"),
|
||
|
|
"revert": ("↩️ Reverts", "revert"),
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def git(*args):
|
||
|
|
r = subprocess.run(["git", *args], capture_output=True, text=True)
|
||
|
|
return r.stdout.strip()
|
||
|
|
|
||
|
|
|
||
|
|
def git_or_none(*args):
|
||
|
|
r = subprocess.run(["git", *args], capture_output=True, text=True)
|
||
|
|
return r.stdout.strip() if r.returncode == 0 else ""
|
||
|
|
|
||
|
|
|
||
|
|
def tag_date(t):
|
||
|
|
return git_or_none("log", "-1", "--format=%ct", t)
|
||
|
|
|
||
|
|
|
||
|
|
def parse_commit(line):
|
||
|
|
"""'abc1234|message' -> (sha, subject)"""
|
||
|
|
if "|" in line:
|
||
|
|
sha, subject = line.split("|", 1)
|
||
|
|
else:
|
||
|
|
sha, subject = line, line
|
||
|
|
return sha, subject
|
||
|
|
|
||
|
|
|
||
|
|
def categorize(subject):
|
||
|
|
subject_l = subject.lower()
|
||
|
|
for prefix, (title, _) in CATEGORIES.items():
|
||
|
|
if subject_l.startswith(prefix + ":") or subject_l.startswith(prefix + "("):
|
||
|
|
return title
|
||
|
|
return "📦 Autres"
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
tag = sys.argv[1] if len(sys.argv) > 1 else git("describe", "--tags", "--abbrev=0") or ""
|
||
|
|
prefix = sys.argv[2] if len(sys.argv) > 2 else "v"
|
||
|
|
repo_url = sys.argv[3] if len(sys.argv) > 3 else "forgejo.tordais.cc"
|
||
|
|
|
||
|
|
# Dernier tag du même préfixe, antérieur à celui-ci (par date du commit tagué)
|
||
|
|
all_tags = [t for t in git("tag", "--list").splitlines() if t.startswith(prefix) and t != tag]
|
||
|
|
all_tags.sort(key=lambda t: (tag_date(t) or "0"), reverse=True)
|
||
|
|
prev = all_tags[0] if all_tags else None
|
||
|
|
|
||
|
|
if prev:
|
||
|
|
raw = git("log", f"{prev}..{tag}", "--pretty=format:%h|%s")
|
||
|
|
elif tag:
|
||
|
|
raw = git("log", tag, "--pretty=format:%h|%s")
|
||
|
|
else:
|
||
|
|
raw = git("log", "--pretty=format:%h|%s")
|
||
|
|
|
||
|
|
commits = [parse_commit(l) for l in raw.splitlines() if l]
|
||
|
|
|
||
|
|
if not commits:
|
||
|
|
print(f"## {tag} — {datetime.date.today().isoformat()}\n\n_No commits._")
|
||
|
|
return 0
|
||
|
|
|
||
|
|
grouped = {}
|
||
|
|
for sha, subject in commits:
|
||
|
|
grouped.setdefault(categorize(subject), []).append((sha, subject))
|
||
|
|
|
||
|
|
today = datetime.date.today().isoformat()
|
||
|
|
lines = [f"## {tag} — {today}", ""]
|
||
|
|
|
||
|
|
for title in ["✨ Features", "🐛 Fixes", "⚡ Performance", "↩️ Reverts", "🧹 Maintenance", "📦 Autres"]:
|
||
|
|
items = grouped.get(title)
|
||
|
|
if not items:
|
||
|
|
continue
|
||
|
|
lines.append(f"### {title}")
|
||
|
|
lines.append("")
|
||
|
|
for sha, subject in items:
|
||
|
|
lines.append(f"- {subject} ([`{sha}`](https://{repo_url}/commit/{sha}))")
|
||
|
|
lines.append("")
|
||
|
|
|
||
|
|
# Liste complète repliable
|
||
|
|
lines.append(f"<details><summary>🔗 {len(commits)} commits</summary>")
|
||
|
|
lines.append("")
|
||
|
|
for sha, subject in commits:
|
||
|
|
lines.append(f"- [`{sha}`](https://{repo_url}/commit/{sha}) {subject}")
|
||
|
|
lines.append("")
|
||
|
|
lines.append("</details>")
|
||
|
|
|
||
|
|
print("\n".join(lines))
|
||
|
|
return 0
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
sys.exit(main())
|