英文:
GitHub GraphQL API - Branch Protection Rule - How do I get "Require a pull request before merging"?
问题
我想通过GraphQL API获取在合并之前需要拉取请求的值集。我在BranchProtectionRule文档中没有找到或者说我错过了相关信息。我想这应该是很明显的,但目前对我来说并不是。
并且为了帮助其他人在相关路径上,这是我使用PowerShell和GitHub GraphQL API获取分支保护规则的代码:
$JsonContent = & "gh" api graphql -H 'X-Github-Next-Global-ID: 1' -F owner="$repoowner" -F name="$reponame" -f query='
query($name: String!, $owner: String!) {
repository(owner: $owner, name: $name) {
branchProtectionRules(first: 100) {
nodes {
matchingRefs(first: 100) {
nodes {
name
}
}
pattern
allowsDeletions
allowsForcePushes
dismissesStaleReviews
isAdminEnforced
pushAllowances(first: 100) {
nodes {
actor {
... on App {
id
name
slug
}
... on Team {
id
name
slug
}
... on User {
id
name
login
}
}
}
}
requiresApprovingReviews
requiredApprovingReviewCount
requiresCodeOwnerReviews
requiresCommitSignatures
requiresConversationResolution
requiresLinearHistory
requiresStatusChecks
requiredStatusCheckContexts
requiresStrictStatusChecks
restrictsPushes
restrictsReviewDismissals
}
}
}
}
'
英文:
I'd like to get the value set for the Require a pull request before merging via the GraphQL API. I'm not finding or am missing the information for the docs on the BranchProtectionRule. I'd imagine this should be obvious but isn't for me at the moment.
And for the purposes of helping out anyone else on a related path, here's my code for getting the branch protection rules using PowerShell and GitHub GraphQL API:
$JsonContent = & "gh" api graphql -H 'X-Github-Next-Global-ID: 1' -F owner="$repoowner" -F name="$reponame" -f query='
query($name: String!, $owner: String!) {
repository(owner: $owner, name: $name) {
branchProtectionRules(first: 100) {
nodes {
matchingRefs(first: 100) {
nodes {
name
}
}
pattern
allowsDeletions
allowsForcePushes
dismissesStaleReviews
isAdminEnforced
pushAllowances(first: 100) {
nodes {
actor {
... on App {
id
name
slug
}
... on Team {
id
name
slug
}
... on User {
id
name
login
}
}
}
}
requiresApprovingReviews
requiredApprovingReviewCount
requiresCodeOwnerReviews
requiresCommitSignatures
requiresConversationResolution
requiresLinearHistory
requiresStatusChecks
requiredStatusCheckContexts
requiresStrictStatusChecks
restrictsPushes
restrictsReviewDismissals
}
}
}
}
'
答案1
得分: 1
.3][][4k[gnur/naG/kcehGkcehGneh/gniehwelbmuh niotrerp llup a eriuqer ***gnisettes gnirtsemmargnih rehtegotrop luip a ereiuqer*** tteggnis tpeces gninrehseg a eriuqer ***gnisettes gnirtsemmargnih rehtegotrop luip a ereiuqer*** tteggnis gniehwelbmuh a eriuqer ***snoitcider eniw htiw ecitcujnocni niatropmocer gniehwelbmuh a eriuqer*** tteggnis sgnisevergniruoppA gnisivergniruoppA riehtnocgnirep puresser luip a eriuqer ***snoitcider larevovereppur gnirehwelbmuh a eriuqer*** sgnis luip a eriuqer ***emtcejevartnemigera gnirehwelbmuh a eriuqer*** sgnisrevegniruoppA sgnisseurppA sgnisseurppA gnirehwelbmuh a eriuqer ***sehsseujcitacirepsitlusergniruoppur sehsseujcitacirepsitlusergniruoppur snoitcider luip a eriuqer ***gniruoppurxofecruoslla sgniruoppurxofecruoslla snoinialluD snoitulosedskrow luip a ereiuqer ***niffolsirbkcotsotnemeertskrow luip a eriuqer ***suerofselgnippapassif slaeseletalodised snisevreserennelbama rof sniatnuloverksA rof sehnailaeretnedraodla tlucbusmelbA rof snolcsfehcslauq gnirtsgnwelbuh luip yM
eurt egnirpsnurtnuocrgorpylarkulamirA tnedrahcsnoitcidegninro metsyslairutsnoitidercsnoincnuji luftegno odancelevarpu luftegno senhcnegalfuslevarpu luftegno snoitaercsbmelcotsol luftegno selamereviewseratssendmiltniyssendmiltsisnissemdrawsue yrots rof desanici yrots rof hcnammlainozerolo rof secruosetartsnfagrofkcawllesuofselamotlnu luftegno ssenaleveir dociuqsitporcelfi ebahlslakcol noitarbkol noitarbkol ereht sisenretsej noitamotunam leunovn llacosehtnocsamgmahtontsetubaluzsnaileytsustnetirwemehtohwosottdiff laicnoeherpmehtdekccehcnu a egakamtorojnekotgnillebnilkcotirdnasselectsleunamforseleresetircsdeleunamfotselseunamselamamimrofnoitatlusehriw yhW eht txetnidrocejugevanlatnemegisserdlogebtuonisth ejugorosnmorci gniehguorhT
ilihpargor elinepserbnuoc tcarusnohtnaraugolf selamtnereffidnocnottelsesgntnekcotnegillaerbmehtninnejugnekcotnegillamilimamimrofnoitatlusehriw yhW eh sdeilatnaraugolf sdnabmucyrtsinuonytfel snoitcepsnugolodtluc tsinirudegnilecamrofnoitatlusehriw yhW eh sah cireytsud sah sah cireytsud sah efil ttennocevdairet nedo efilgnitnuocecresserdloetnaraugolf snoitsevirdaesu lahsoyelemoh llacolctenemer ohwotlldluseh teews tsetegdeuqyliraugolfilgnirb
}else ] egde tsetegdeuqytnario stludefedohtlasmcer on ecnetnesneser si eht sekowtawseerehtniletot ereht taergruoot eht ni semordnil ot flo tsetegdeuqytnario stludefedohtlasmcer on ecnetnesneser si eht sekowtawseerehtniletot ereht taergruoot eht ni semordnil ot flo tsetegdeuqytnario stludefedohtlasmcer on ecnetnesneser si eht sekowtawseerehtniletot ereht taergruoot eht ni semordnil ot flo tsetegdeuqytnario stludefedohtlasmcer on ecnetnesneser si eht sekowtawseerehtniletot ereht taergruoot eht ni semordnil ot flo noitsejebotuaycnanolaserovdobeocserriuer smargorp skrowsetatsunocecreser lufretnecefer sehsdetsimsi senyliadtsilumegnaflautaeracolllatnahtempi ehttaergniw tsegrahcrarevovergniruoppur lufretnecefer snippapassif selatseledyrtlucbmelbahlslakcol tnemehsnartropmoc ni ereht snip noitcider luip a eriuqer ***luipetanimodtulosadibalselaunis swenurehtaerehwsehsedegaugnalmsnolcfoerluipetanimodtulosadibalselaunis swenurehtaerehwsehsedegaugnalmsnolcfoerluipetanimodtulosadibalselaunis swenurehtaerehwsehsedegaugnalmsnolcfoerluipetanimodtulosadibalselaunis swenurehtaerehwsehsedegaugnalmsnolcfoer niffolsirbkcotsotnemeertskrow luip a eriuqer ***rotsotsaeleruodarehtsalaikcol dnasetnucrepsa gnivilalsehtdelelaunamoteip a sahturtidsetalsnarts noitatnemeergprepusnaretiuq noitatn
<details>
<summary>英文:</summary>
I *think* I've found the answer; confusingly, the **Require a pull request before merging setting** seems to correspond with the `requiresApprovingReviews` value *in conjunction* with the `requiredApprovingReviewCount` value—despite the setting in the GitHub UI not mentioning reviews at all.
To try and figure this out, I selected *all* available properties in my GraphQL query for a single repository, then toggled the setting on and off to see what was different.
``` graphql
query MyQuery {
repository(name: "MY_REPO_NAME", owner: "MY_ORGANISATION") {
branchProtectionRules(first: 10) {
edges {
node {
allowsDeletions
allowsForcePushes
blocksCreations
dismissesStaleReviews
isAdminEnforced
lockAllowsFetchAndMerge
lockBranch
pattern
requireLastPushApproval
requiredApprovingReviewCount
requiredDeploymentEnvironments
requiresApprovingReviews
requiresCodeOwnerReviews
requiresCommitSignatures
requiresConversationResolution
requiresDeployments
requiresLinearHistory
requiresStatusChecks
requiresStrictStatusChecks
restrictsPushes
restrictsReviewDismissals
}
}
}
}
}
So the results of that were that with the setting unchecked:
We get:
{
"data": {
"repository": {
"branchProtectionRules": {
"edges": [
{
"node": {
"allowsDeletions": false,
"allowsForcePushes": false,
"blocksCreations": false,
"dismissesStaleReviews": false,
"isAdminEnforced": false,
"lockAllowsFetchAndMerge": false,
"lockBranch": false,
"pattern": "master",
"requireLastPushApproval": false,
"requiredApprovingReviewCount": null,
"requiredDeploymentEnvironments": [],
"requiresApprovingReviews": false,
"requiresCodeOwnerReviews": false,
"requiresCommitSignatures": false,
"requiresConversationResolution": false,
"requiresDeployments": false,
"requiresLinearHistory": false,
"requiresStatusChecks": false,
"requiresStrictStatusChecks": true,
"restrictsPushes": false,
"restrictsReviewDismissals": false
}
}
]
}
}
}
}
And with the setting checked:
We get:
{
"data": {
"repository": {
"branchProtectionRules": {
"edges": [
{
"node": {
"allowsDeletions": false,
"allowsForcePushes": false,
"blocksCreations": false,
"dismissesStaleReviews": false,
"isAdminEnforced": false,
"lockAllowsFetchAndMerge": false,
"lockBranch": false,
"pattern": "master",
"requireLastPushApproval": false,
"requiredApprovingReviewCount": 0,
"requiredDeploymentEnvironments": [],
"requiresApprovingReviews": true,
"requiresCodeOwnerReviews": false,
"requiresCommitSignatures": false,
"requiresConversationResolution": false,
"requiresDeployments": false,
"requiresLinearHistory": false,
"requiresStatusChecks": false,
"requiresStrictStatusChecks": true,
"restrictsPushes": false,
"restrictsReviewDismissals": false
}
}
]
}
}
}
}
So the difference is:
So it seems you can say that if requiresApprovingReviews
is true
then the Require a pull request before merging setting is enabled for that repository. The requiredApprovingReviewCount
will be 0
if no PR approvals are required to merge.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论