Compare commits

...

1 Commits

Author SHA1 Message Date
kimi
9acc0150f1 fix: auto-detect issue number from git branch in cycle_retro
All checks were successful
Tests / lint (pull_request) Successful in 3s
Tests / test (pull_request) Successful in 1m21s
When --issue is not provided, cycle_retro.py now parses the current
git branch name (e.g. kimi/issue-492) to extract the issue number.
This prevents all retro records from having issue=null when the
caller omits the flag.

Fixes #492

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-19 16:16:43 -04:00

View File

@@ -44,6 +44,8 @@ from __future__ import annotations
import argparse import argparse
import json import json
import re
import subprocess
import sys import sys
from datetime import datetime, timezone from datetime import datetime, timezone
from pathlib import Path from pathlib import Path
@@ -97,6 +99,27 @@ def _epoch_tag(now: datetime | None = None) -> tuple[str, dict]:
return tag, parts 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: def parse_args() -> argparse.Namespace:
p = argparse.ArgumentParser(description="Log a cycle retrospective") p = argparse.ArgumentParser(description="Log a cycle retrospective")
p.add_argument("--cycle", type=int, required=True) p.add_argument("--cycle", type=int, required=True)
@@ -230,6 +253,13 @@ def update_summary() -> None:
def main() -> None: def main() -> None:
args = parse_args() 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 # Reject idle cycles — no issue and no duration means nothing happened
if not args.issue and args.duration == 0: if not args.issue and args.duration == 0:
print(f"[retro] Cycle {args.cycle} skipped — idle (no issue, no duration)") print(f"[retro] Cycle {args.cycle} skipped — idle (no issue, no duration)")