Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Pilot Lvl 1
Message 1 of 2

GraphQL API Protected branch

Solved! Go to Solution.

I am using a GITHUB API V3 in one of my project now we are migrating to GraraphQL API V4. I want to list all the branches of the repo and i want to check wether it is protected branch. In GITHUB API V3 it has a branches api that will list all the branches along with it is protected key so it was each to check. Now in GraphQL i can get all the branches list but i can't check wether the branch is protected or not.

 

       refs(first: 100, refPrefix: "refs/heads/") {
        	nodes {
        		name
        	}
        }

 

Someone could assist on this how to proceed?

 

If that could not be achieved by the `refs` then is there a way to list all the protected branches alone

 

Regards

Parithiban

1 Reply
Solution
Community Manager
Message 2 of 2

Re: GraphQL API Protected branch

You can use the following query to get the list of branch protection rules (and what branches they match) and the list of all branches for a repository:

 

{
  repository(owner: "atom", name: "atom") {
    branchProtectionRules(first: 100) {
      nodes {
        pattern
        matchingRefs(first: 100) {
          nodes {
            name
          }
        }
      }
    }
    refs(first: 100, refPrefix: "refs/heads/") {
      nodes {
        name
      }
    }
  }
}

I hope that helps! Let us know if you have more questions.