diff --git a/scripts/cycle_retro.py b/scripts/cycle_retro.py index 0803ce1..6b40fff 100644 --- a/scripts/cycle_retro.py +++ b/scripts/cycle_retro.py @@ -44,6 +44,8 @@ from __future__ import annotations import argparse import json +import re +import subprocess import sys from datetime import datetime, timezone from pathlib import Path @@ -97,6 +99,27 @@ def _epoch_tag(now: datetime | None = None) -> tuple[str, dict]: return tag, parts +BRANCH_ISSUE_RE = re.compile(r"issue-(\d+)") + + +def _detect_issue_from_branch() -> int | None: + """Try to extract an issue number from the current git branch name. + + Matches branch patterns like ``kimi/issue-492`` or ``fix/issue-17``. + Returns ``None`` when not on a matching branch or git is unavailable. + """ + try: + branch = subprocess.check_output( + ["git", "rev-parse", "--abbrev-ref", "HEAD"], + stderr=subprocess.DEVNULL, + text=True, + ).strip() + except (subprocess.CalledProcessError, FileNotFoundError): + return None + m = BRANCH_ISSUE_RE.search(branch) + return int(m.group(1)) if m else None + + def parse_args() -> argparse.Namespace: p = argparse.ArgumentParser(description="Log a cycle retrospective") p.add_argument("--cycle", type=int, required=True) @@ -230,6 +253,13 @@ def update_summary() -> None: def main() -> None: args = parse_args() + # Auto-detect issue from branch name when not explicitly provided + if args.issue is None: + detected = _detect_issue_from_branch() + if detected is not None: + args.issue = detected + print(f"[retro] Auto-detected issue #{detected} from branch name") + # Reject idle cycles — no issue and no duration means nothing happened if not args.issue and args.duration == 0: print(f"[retro] Cycle {args.cycle} skipped — idle (no issue, no duration)")