Skip to content

Commit 5ea0394

Browse files
committed
fix: preserve existing status check contexts during branch protection sync
The PUT endpoint replaces all branch protection. Without this fix, repos without an explicit override in overrides.json would have their status check contexts wiped to an empty array. Now the script reads the current contexts from the repo and carries them forward.
1 parent d83bc29 commit 5ea0394

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

scripts/sync-repo-settings.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,22 @@ apply_branch_protection() {
261261
local branch="$2"
262262
local effective="$3"
263263

264+
# Preserve existing status check contexts if no override is defined.
265+
# The PUT endpoint replaces all protection, so we must carry forward
266+
# the repo's current contexts to avoid wiping repo-specific CI checks.
264267
local contexts="[]"
265268
local override_contexts
266269
override_contexts=$(jq -r --arg r "$repo" '.repos[$r].branch_protection.required_status_checks.contexts // empty' "$OVERRIDES" 2>/dev/null || echo "")
267270
if [ -n "$override_contexts" ]; then
268271
contexts=$(jq -r --arg r "$repo" '.repos[$r].branch_protection.required_status_checks.contexts' "$OVERRIDES")
272+
else
273+
# No override — read current contexts from the repo so we don't wipe them
274+
local current_contexts
275+
current_contexts=$(gh api "repos/$OWNER/$repo/branches/$branch/protection/required_status_checks" --jq '.contexts // []' 2>/dev/null || echo "[]")
276+
if [ -n "$current_contexts" ] && [ "$current_contexts" != "[]" ]; then
277+
contexts="$current_contexts"
278+
log "INFO: Preserving existing status check contexts for $repo"
279+
fi
269280
fi
270281

271282
local strict

0 commit comments

Comments
 (0)