CICD-415 · Branch protection automation
Encyclopedia · Platform engineering and internal developer platforms · All snippets
Previous · CICD-414 · Next · CICD-416
1. Where it fits
- Placement CI run step or authorized lab terminal.
- Prerequisites platform sandbox, scoped identities and reviewed service catalog or provisioning policy.
- Platforms kubernetes, local-lab.
- Parameters
TARGET_REPO.
2. Copy the snippet
bash
gh api "repos/${TARGET_REPO:?}/branches/main/protection/required_status_checks" --jq '.strict and ([.checks[].context] | index("ci") != null)' | grep -Fx true3. How it works
The CLI calls the named GitHub API endpoint using current repository and token permissions. The expression filters or transforms the input JSON. Where jq -e is used, a false or empty result can fail the gate.
4. Verify the result
Read and verify policy before a separate configuration rollout. A ruleset-managed repository needs its ruleset API instead.
Validation syntax-validated (Bash parse). Status definitions.