graphqlbranchgithub-apigithub-api-v4

GraphQL API Protected branch


I am using a GITHUB API V3 in one of my projects now we are migrating to GraraphQL API V4. I want to list all the branches of the repo and I want to check whether it is a 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 easy to check. Now in GraphQL, I can get all the branches list but I can't check whether the branch is protected or not.

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

Someone could assist with this on how to proceed?

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


Solution

  • I found out the logic to get the protected branch

    {
        viewer {
            repository(owner: "parithiban", name: "git-slack-bot") {
                branchProtectionRules(first: 5) {
                    nodes {
                        pattern
                        requiredApprovingReviewCount
                        matchingRefs(first: 100) {
                            nodes {
                                name
                            }
                        }
                    }
                }
            }
        }
    }