GraphQL API Protected branch #24640
-
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.
Someone could assist on this how to proceed? If that could not be achieved by the Regards Parithiban |
Beta Was this translation helpful? Give feedback.
Replies: 20 comments 2 replies
-
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:
I hope that helps! Let us know if you have more questions. |
Beta Was this translation helpful? Give feedback.
-
Hello, how can i use the same kind of pattern to protect my branch with wildcard rules like: release* I am trying. to use API call for this |
Beta Was this translation helpful? Give feedback.
-
See the below example to create a branch protection rule. You can change *pari* with release* You can check the output in the settings tab and clicking branches options in your repo. |
Beta Was this translation helpful? Give feedback.
-
@parithiban thanks a lot that’s what I was looking for |
Beta Was this translation helpful? Give feedback.
-
Does github have api to see who can push to the protected branch? I am looking at pushAllowances but couldn’t figure it out. The fix is to use fragment: something like
|
Beta Was this translation helpful? Give feedback.
-
If I get your point correctly. You need to get the list of users who can push to the protected branch You can follow the below steps:
Hope this answers your query. |
Beta Was this translation helpful? Give feedback.
-
question regarding to https://developer.github.com/v4/input_object/deletebranchprotectionruleinput/ what is the I tried to add the repository node_id did not work, any suggestion?
|
Beta Was this translation helpful? Give feedback.
-
First, you need to get the branch protection id then you can pass that to the mutation input parameter To get the branch protection id see below Then you need to pass that branch protection id.
By applying the above query your branch protection will be deleted. |
Beta Was this translation helpful? Give feedback.
-
how can we add user to the branch protection like this? @parithiban |
Beta Was this translation helpful? Give feedback.
-
this is not working for me |
Beta Was this translation helpful? Give feedback.
-
You can try with the following query
|
Beta Was this translation helpful? Give feedback.
-
parithiban:
@parithiban this does not work
|
Beta Was this translation helpful? Give feedback.
-
You need to slightly modify your query
branchProtectionRule node has id paramaeter and not branchProtectionRuleId |
Beta Was this translation helpful? Give feedback.
-
This worked @parithiban Thanks |
Beta Was this translation helpful? Give feedback.
-
@parithiban by running this i get this error:
|
Beta Was this translation helpful? Give feedback.
-
What is the mutation query that you are trying to execute? |
Beta Was this translation helpful? Give feedback.
-
this is what i run |
Beta Was this translation helpful? Give feedback.
-
As the error suggests it should have a selection of subfields. Can you try with the below query?
|
Beta Was this translation helpful? Give feedback.
-
that is working thanks a lot for your help and being so helpful as always |
Beta Was this translation helpful? Give feedback.
-
can someone help to get the branch protection rule id for one of the rules like, I have branch protection rule 'test*' and I want to get the branch protection rule id for this one, can someone help me, please |
Beta Was this translation helpful? Give feedback.
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:
I hope that helps! Let us know if you have more questions.