✨ feat(pr-autocreate): refuse a push to a retired branch, 0.6.18

Merged
AT
16d ago
+295-23

Slice: #327

athya_mono's pr-autocreate.py gained a fourth mode, refuse-retired, after niyam 0.6.17 was cut. It came in athya-hq/athya_mono#3664 (0165 L-04). This slice moves that file to niyam, and athya_mono deletes its copy only once niyam refuses the same planted mistake. So the mode comes over here, released as 0.6.18.

What changes

  • niyam pr-autocreate refuse-retired --root <repo> --remote <name>. The pre-push hook runs it before its expensive checks, with git's ref lines on stdin.
    • It refuses (exit 3) a push to a branch whose PR merged while none is open. Pushing such a branch recreates what the merge retired, and the commits after the merge land in no PR.
    • The refusal names the way out. That is the new retire setting, a command with {number}, or else the retired page.
    • It judges no deletion, tag, protected or queue branch, other remote, or CI push.
  • It fails open, as athya's does. A GitHub error, or a full page of 20 PRs (counted before the head filter, so other heads filling the page count too), only warns.
    • A crash, bad arguments or unreadable settings exit 4 ("not checked"), never the 0 of a live branch.
  • One rule. retiredBy is shared by ensurePr and the new mode. Pulls.listing returns the pulls and whether the page was full, and Pulls.list wraps it.
  • pushedRefs reads the ref lines for spawn-watchers and refuse-retired alike.
  • Docs and version. README, pr-autocreate section, and 0.6.18 in package.json and the install link.

Evidence

  • node --test src/pr-autocreate.test.ts: 70 pass, 9 of them new:
    • the L-04 refusal and its message;
    • the retire and retired way-out lines;
    • live branches (open after merged, closed unmerged, none);
    • pushes it doesn't judge, asking GitHub nothing;
    • one ask per branch;
    • a 502, a full page, and a full page made of other heads;
    • exit 4 on bad arguments, settings, or a crash;
    • retiredBy and pushedRefs.
  • pnpm check passes. Coverage is 99.65 / 97.47 / 98.83 (lines / branches / functions). node dist/cli.js --version prints 0.6.18.
  • Parity with athya_mono's refuse_retired:
    • same refs judged, same CI and remote exemption;
    • same exit codes (3 refuse, 4 crash);
    • the first two message lines are word for word.

State #328 ("Release ships pr-autocreate") stays open until athya_mono pins this release, in athya-hq/athya_mono#3646.

🤖 Generated with Claude Code


Summary by cubic

Adds refuse-retired mode to niyam pr-autocreate so the pre-push hook refuses pushes to branches whose PR already merged while none is open. The refusal names the way out, from the new retire setting or the existing retired page. Bumps the package to 0.6.18.

  • Exits 3 on refusal; GitHub errors and a full page of PRs only warn; crashes exit 4, never the 0 of a live branch.
  • Deletions, tags, protected branches, other remotes, and CI pushes pass without asking GitHub.
  • ensurePr and the new mode share one retiredBy rule; pushedRefs reads the ref lines for both spawn-watchers and refuse-retired.
  • retire must name the merged PR as {number}; adopter moves the commits missing from the PR head to a fresh branch.