Skip to content

Commit d692ec9

Browse files
hyperpolymathclaude
andcommitted
fix(branch-protection): stop reverting security remediation + clobbering repo checks
build_payload() previously did a wholesale full-body PUT that, on every run: 1. re-added a code_scanning (CodeQL) merge-protection rule — GitHub's code-scanning gate is flaky (perpetually 'expects results'), deadlocking PRs into admin-only merges; 2. re-added admin bypass_mode='always' + three Integration bypass actors (29110/1143301/1236702), REVERTING the 2026-06-29 bypass-actor security remediation; 3. wrote an empty required_status_checks, WIPING each repo's own gates (e.g. a Rust repo's 'analyze (rust, none)' + 'llvm-cov line coverage'). Now: - no code_scanning rule (CodeQL enforced via a required_status_check instead); - bypass_actors = admin (RepositoryRole 5) at 'pull_request' only; - apply_one() reads the repo's existing required_status_checks and passes them to build_payload, so standardising is ADDITIVE (repairs the invariant baseline) and never clobbers per-repo gates. Verified: payload is valid JSON, carries no code_scanning, single admin pull_request bypass, and preserves supplied per-repo checks. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 5747de8 commit d692ec9

1 file changed

Lines changed: 24 additions & 12 deletions

File tree

scripts/branch-protection-apply.sh

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,25 @@ fi
8585
# -----------------------------------------------------------------------------
8686

8787
build_payload() {
88-
cat <<'JSON'
88+
# $1 = the repo's EXISTING required_status_checks array (JSON). Preserved so
89+
# this standardiser repairs the invariant baseline WITHOUT clobbering the
90+
# per-repo status checks a repo has legitimately added (e.g. rust/coverage).
91+
#
92+
# Deliberately NOT included here:
93+
# - bypass_actors Integration entries + admin "always": re-adding those
94+
# reverts the 2026-06-29 bypass-actor security remediation. Admin keeps a
95+
# "pull_request" bypass only.
96+
# - a code_scanning rule: GitHub's code-scanning merge-protection is flaky
97+
# (perpetually "expects results", deadlocking PRs). CodeQL is enforced via
98+
# a required_status_check instead, preserved per-repo above.
99+
local existing_checks="${1:-[]}"
100+
cat <<JSON
89101
{
90102
"name": "Base",
91103
"target": "branch",
92104
"enforcement": "active",
93105
"bypass_actors": [
94-
{"actor_id": 5, "actor_type": "RepositoryRole", "bypass_mode": "always"},
95-
{"actor_id": 29110, "actor_type": "Integration", "bypass_mode": "always"},
96-
{"actor_id": 1143301, "actor_type": "Integration", "bypass_mode": "always"},
97-
{"actor_id": 1236702, "actor_type": "Integration", "bypass_mode": "always"}
106+
{"actor_id": 5, "actor_type": "RepositoryRole", "bypass_mode": "pull_request"}
98107
],
99108
"conditions": {
100109
"ref_name": {"include": ["~DEFAULT_BRANCH"], "exclude": []}
@@ -109,12 +118,7 @@ build_payload() {
109118
{"type": "required_status_checks",
110119
"parameters": {"strict_required_status_checks_policy": false,
111120
"do_not_enforce_on_create": true,
112-
"required_status_checks": []}},
113-
{"type": "code_scanning",
114-
"parameters": {"code_scanning_tools": [
115-
{"tool": "CodeQL",
116-
"alerts_threshold": "errors",
117-
"security_alerts_threshold": "high_or_higher"}]}}
121+
"required_status_checks": ${existing_checks}}}
118122
]
119123
}
120124
JSON
@@ -146,7 +150,15 @@ apply_one() {
146150
return 0
147151
fi
148152

149-
local payload; payload="$(build_payload)"
153+
# Read the repo's own required status checks so the standardiser is additive
154+
# (repairs the baseline rules) rather than wiping per-repo gates on the PUT.
155+
local existing_checks='[]'
156+
if [[ -n "${existing_id}" ]]; then
157+
existing_checks="$(gh api "repos/${OWNER}/${repo_name}/rulesets/${existing_id}" \
158+
--jq '([.rules[]? | select(.type=="required_status_checks") | .parameters.required_status_checks] | add) // []' 2>/dev/null || echo '[]')"
159+
[[ -z "${existing_checks}" || "${existing_checks}" == "null" ]] && existing_checks='[]'
160+
fi
161+
local payload; payload="$(build_payload "${existing_checks}")"
150162
local attempt
151163
for attempt in 1 2; do
152164
if gh api "${url}" --method "${method}" --input - <<< "${payload}" >/dev/null 2>&1; then

0 commit comments

Comments
 (0)