Skip to content

Instantly share code, notes, and snippets.

@KyMidd

KyMidd/asdf.sh Secret

Created November 20, 2022 18:59
Show Gist options
  • Select an option

  • Save KyMidd/da2df574cb56af2b493a0dac71f066f6 to your computer and use it in GitHub Desktop.

Select an option

Save KyMidd/da2df574cb56af2b493a0dac71f066f6 to your computer and use it in GitHub Desktop.
if [[ "$MASTER_EXISTS" = true ]]; then
unset BRANCH
BRANCH=master
unset CURL
CURL=$(curl -s \
-X PUT \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
https://api.github.com/repos/$GH_ORG/$GH_REPO/branches/$BRANCH/protection \
-d "{\"required_status_checks\":{\"strict\":true,\"checks\":[{\"context\":\"name_of_status_check\"}]},\"restrictions\":{\"users\":[],\"teams\":[],\"apps\":[]},\"required_signatures\":false,\"required_pull_request_reviews\":{\"dismiss_stale_reviews\":true,\"require_code_owner_reviews\":true,\"required_approving_review_count\":$REQUIRED_APPROVERS_COUNT,\"require_last_push_approval\":true,\"bypass_pull_request_allowances\":{\"users\":[],\"teams\":[],\"apps\":[]}},\"enforce_admins\":true,\"required_linear_history\":false,\"allow_force_pushes\":false,\"allow_deletions\":false,\"block_creations\":false,\"required_conversation_resolution\":true,\"lock_branch\":false,\"allow_fork_syncing\":false}" 2>&1)
if [[ $(echo "$CURL" | grep -E "Problems|Not Found") ]]; then
echo "☠️ Something bad happened setting branch protections on $BRANCH, please investigate response:"
echo "$CURL"
else
echo "💥 Successfully set branch protections on $BRANCH"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment