Skip to content

Instantly share code, notes, and snippets.

@wuhuizuo
Last active April 9, 2025 08:58
Show Gist options
  • Save wuhuizuo/02e15cf574cbeebc122894468e204edf to your computer and use it in GitHub Desktop.
Save wuhuizuo/02e15cf574cbeebc122894468e204edf to your computer and use it in GitHub Desktop.
how to list branch protection rules of a repo
query ($owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) {
branchProtectionRules(first: 100) {
nodes {
pattern
requiresApprovingReviews
requiredApprovingReviewCount
requiresStatusChecks
requiredStatusCheckContexts
requiresStrictStatusChecks
requiresCodeOwnerReviews
dismissesStaleReviews
restrictsReviewDismissals
restrictsPushes
allowsDeletions
allowsForcePushes
isAdminEnforced
}
}
}
}
# 1. create the query graphql file
# 2. run with gh cli:
gh api graphql -F [email protected] -F owner=<owner> -F repo=<repo> --jq '.data.repository.branchProtectionRules.nodes' | tee bp.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment