2026-08-18 08:22:47 +02:00
|
|
|
#!/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).
|
|
|
|
|
"""
|
2026-08-30 10:09:55 +02:00
|
|
|
import re
|
2026-08-18 08:22:47 +02:00
|
|
|
import subprocess
|
|
|
|
|
import sys
|
|
|
|
|
import datetime
|
|
|
|
|
|
2026-08-30 10:09:55 +02:00
|
|
|
|
2026-08-18 08:22:47 +02:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
2026-08-30 10:09:55 +02:00
|
|
|
def detect_repo():
|
|
|
|
|
"""Détecte owner/repo depuis le remote git origin."""
|
|
|
|
|
url = git_or_none("remote", "get-url", "origin")
|
|
|
|
|
if not url:
|
|
|
|
|
return None
|
|
|
|
|
# https://host/owner/repo.git ou git@host:owner/repo.git
|
|
|
|
|
m = re.search(r'[:/]([^/]+)/([^/]+?)(?:\.git)?$', url)
|
|
|
|
|
if m:
|
|
|
|
|
return f"{m.group(1)}/{m.group(2)}"
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
2026-08-18 08:22:47 +02:00
|
|
|
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"
|
|
|
|
|
|
|
|
|
|
|
2026-08-30 10:09:55 +02:00
|
|
|
def link_issues(subject, forgejo_url, repo_slug):
|
|
|
|
|
"""Convertit les références #N en liens cliquables — scan unique sans double-processing.
|
|
|
|
|
|
|
|
|
|
Formats gérés (par priorité) :
|
|
|
|
|
- Fixes/Closes/Resolves/Refs/See #61 → [Fixes #61](URL)
|
|
|
|
|
- (#154) → [(#154)](URL)
|
|
|
|
|
- #42 standalone → [#42](URL)
|
|
|
|
|
"""
|
|
|
|
|
if not repo_slug:
|
|
|
|
|
return subject
|
|
|
|
|
|
|
|
|
|
base = f"https://{forgejo_url}/{repo_slug}/issues"
|
|
|
|
|
|
|
|
|
|
# Scan unique : tous les patterns dans un seul regex, groupes nommés
|
|
|
|
|
combined = re.compile(
|
|
|
|
|
r'(?P<kw>(?:Fixes|Closes|Resolves|Refs|See)\s+#(?P<kw_n>\d+))'
|
|
|
|
|
r'|\(#(?P<paren_n>\d+)\)'
|
|
|
|
|
r'|(?<!\w)#(?P<stand_n>\d+)\b'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Collecte de toutes les insertions (offset → replacement)
|
|
|
|
|
insertions = []
|
|
|
|
|
for m in combined.finditer(subject):
|
|
|
|
|
if m.group('kw'):
|
|
|
|
|
kw_text, num = m.group('kw'), m.group('kw_n')
|
|
|
|
|
replacement = f"[{kw_text}]({base}/{num})"
|
|
|
|
|
elif m.group('paren_n'):
|
|
|
|
|
num = m.group('paren_n')
|
|
|
|
|
replacement = f"[(#{num})]({base}/{num})"
|
|
|
|
|
else:
|
|
|
|
|
num = m.group('stand_n')
|
|
|
|
|
replacement = f"[#{num}]({base}/{num})"
|
|
|
|
|
insertions.append((m.start(), m.end(), replacement))
|
|
|
|
|
|
|
|
|
|
if not insertions:
|
|
|
|
|
return subject
|
|
|
|
|
|
|
|
|
|
# Reconstruction de la chaîne en une passe
|
|
|
|
|
parts = []
|
|
|
|
|
prev_end = 0
|
|
|
|
|
for start, end, repl in insertions:
|
|
|
|
|
parts.append(subject[prev_end:start])
|
|
|
|
|
parts.append(repl)
|
|
|
|
|
prev_end = end
|
|
|
|
|
parts.append(subject[prev_end:])
|
|
|
|
|
return "".join(parts)
|
|
|
|
|
|
|
|
|
|
|
2026-08-18 08:22:47 +02:00
|
|
|
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"
|
2026-08-30 10:09:55 +02:00
|
|
|
forgejo_url = sys.argv[3] if len(sys.argv) > 3 else "forgejo.tordais.cc"
|
|
|
|
|
|
|
|
|
|
# Détection automatique owner/repo pour les liens issues
|
|
|
|
|
repo_slug = detect_repo()
|
2026-08-18 08:22:47 +02:00
|
|
|
|
|
|
|
|
# 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:
|
2026-08-30 10:09:55 +02:00
|
|
|
linked = link_issues(subject, forgejo_url, repo_slug)
|
|
|
|
|
lines.append(f"- {linked} ([`{sha}`](https://{forgejo_url}/commit/{sha}))")
|
2026-08-18 08:22:47 +02:00
|
|
|
lines.append("")
|
|
|
|
|
|
|
|
|
|
# Liste complète repliable
|
|
|
|
|
lines.append(f"<details><summary>🔗 {len(commits)} commits</summary>")
|
|
|
|
|
lines.append("")
|
|
|
|
|
for sha, subject in commits:
|
2026-08-30 10:09:55 +02:00
|
|
|
linked = link_issues(subject, forgejo_url, repo_slug)
|
|
|
|
|
lines.append(f"- [`{sha}`](https://{forgejo_url}/commit/{sha}) {linked}")
|
2026-08-18 08:22:47 +02:00
|
|
|
lines.append("")
|
|
|
|
|
lines.append("</details>")
|
|
|
|
|
|
|
|
|
|
print("\n".join(lines))
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
sys.exit(main())
|