fix(branch-protection-sync): exit-code state detection + preserve existing checks - #1767
Conversation
…sting checks Three bugs found verifying the dry-run before any fleet-wide apply: 1. State detection read output-emptiness, but `gh api` prints the 404 error JSON to stdout — so every branch mis-read as "protected" and only_unprotected would skip everything. Now branches on the gh api EXIT CODE. 2. The policy nulled required_status_checks unconditionally — a broad apply would WIPE the checks on the 3 forks that actually gate on CI (Agent-Zero/Archon/DoX). Now reads + PRESERVES existing required checks; naked branches stay null. 3. The policy() heredoc terminator was indented (`<<JSON` needs col-0), so it would never terminate on the first real apply. Rebuilt with jq — always-valid JSON, $rsc injected as real JSON. Also: private repos that 403 with "Upgrade to GitHub Pro" are now SKIPPED + counted (not mis-attributed to a missing admin grant). Verified locally against the live API: supabase=protected[0], Agent-Zero=protected[3] (checks preserved verbatim), tensorzero=UNPROTECTED, space-agent=SKIP(needs-pro). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 44 minutes and 17 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff50ac5399
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # Preserve existing required checks verbatim. | ||
| rsc=$(printf '%s' "$cur" | jq -c 'if .required_status_checks then {strict: .required_status_checks.strict, contexts: .required_status_checks.contexts} else null end' 2>/dev/null) | ||
| [ -z "$rsc" ] && rsc="null" | ||
| elif grep -qiE 'Upgrade to GitHub Pro|make this repository public' /tmp/bp_err; then |
There was a problem hiding this comment.
Check stdout for Pro-only protection errors
Here grep only examines /tmp/bp_err, but this GET captures gh api stdout into cur and redirects only stderr; the new comment above also notes that gh api prints HTTP error JSON to stdout, and the gh api manual describes the command as printing the API response. For private repos whose 403 body contains “Upgrade to GitHub Pro” on stdout, this branch never matches, so dry-runs report them as UNPROTECTED and apply runs try the PUT and count a failure instead of the intended s skipped(needs-pro). Check cur as well, or capture stdout and stderr into the same buffer before falling through.
Useful? React with 👍 / 👎.
…k-sync campaign Control-Body bookkeeping for the 2026-06-09→11 Z890 main-infra campaign (the docs lagged it by a week). For 4090-CLAUDE pair-review. - Claim register: new RELEASE section logging the campaign — supabase CRITICAL sync (#1761/#1768), branch-protection automation (#1760/#1767, 31 forks), full fork-sync clearance (auto-tier + high-ahead + ClawZ 8354c/Creator), Archon CI green (#19 lint / #20 E2E), space-agent public+protected. - README Known Gaps: retire stale entries — OBSERVABILITY_MAP.md now on main (P2 resolved), A2A exposure wired into compose (P0 → runtime-verify only), NATS-auth closed NON-URGENT (#1690, 23 refs left). Added fleet-governance state note. - SITREP: +2 June wave rows (Main-Infra Pass, Fleet Fork-Sync + Governance), refreshed date 2026-05-27 → 2026-06-11, title Apr–May → Apr–Jun. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…k-sync campaign (#1786) Control-Body bookkeeping for the 2026-06-09→11 Z890 main-infra campaign (the docs lagged it by a week). For 4090-CLAUDE pair-review. - Claim register: new RELEASE section logging the campaign — supabase CRITICAL sync (#1761/#1768), branch-protection automation (#1760/#1767, 31 forks), full fork-sync clearance (auto-tier + high-ahead + ClawZ 8354c/Creator), Archon CI green (#19 lint / #20 E2E), space-agent public+protected. - README Known Gaps: retire stale entries — OBSERVABILITY_MAP.md now on main (P2 resolved), A2A exposure wired into compose (P0 → runtime-verify only), NATS-auth closed NON-URGENT (#1690, 23 refs left). Added fleet-governance state note. - SITREP: +2 June wave rows (Main-Infra Pass, Fleet Fork-Sync + Governance), refreshed date 2026-05-27 → 2026-06-11, title Apr–May → Apr–Jun. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Follow-up to #1760. Found three bugs by verifying the dry-run (run 27227095327) before any fleet-wide apply — none would have surfaced in dry-run alone:
gh apiprints the 404 error JSON to stdout, so testing output-emptiness mis-read every branch as "protected" →only_unprotectedwould skip everything. Now branches on the gh api exit code.required_status_checksunconditionally; a broad apply would wipe the checks on the 3 forks that actually gate on CI (Agent-Zero=3, Archon=2, DoX=2). Now preserves existing required checks; naked branches stay null.policy()'s<<JSONterminator was indented (needs col-0), so it would never terminate on the first real apply (dry-run returns before calling it, so it was latent). Rebuilt with jq — always-valid JSON,$rscinjected as real JSON.Plus: private repos that 403 with "Upgrade to GitHub Pro" are now skipped + counted (not mis-blamed on a missing admin grant —
PMOVES-space-agent).Verified locally against the live API before pushing:
protected[checks=0]protected[checks=3]{"contexts":["audit","lint","security-scan"]}✅UNPROTECTEDSKIP(needs-pro)After merge: dry-run → apply
only_unprotected=trueto protect the ~33 naked forks (preserving the 3 good ones).🤖 Generated with Claude Code