GitHub GraphQL API – 分支保护规则 – 如何获取“在合并之前需要拉取请求”?

huangapple go评论57阅读模式
英文:

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.

GitHub GraphQL API – 分支保护规则 – 如何获取“在合并之前需要拉取请求”?

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&#39;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: &quot;MY_REPO_NAME&quot;, owner: &quot;MY_ORGANISATION&quot;) {
    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:

GitHub GraphQL API – 分支保护规则 – 如何获取“在合并之前需要拉取请求”?

We get:

{
  &quot;data&quot;: {
    &quot;repository&quot;: {
      &quot;branchProtectionRules&quot;: {
        &quot;edges&quot;: [
          {
            &quot;node&quot;: {
              &quot;allowsDeletions&quot;: false,
              &quot;allowsForcePushes&quot;: false,
              &quot;blocksCreations&quot;: false,
              &quot;dismissesStaleReviews&quot;: false,
              &quot;isAdminEnforced&quot;: false,
              &quot;lockAllowsFetchAndMerge&quot;: false,
              &quot;lockBranch&quot;: false,
              &quot;pattern&quot;: &quot;master&quot;,
              &quot;requireLastPushApproval&quot;: false,
              &quot;requiredApprovingReviewCount&quot;: null,
              &quot;requiredDeploymentEnvironments&quot;: [],
              &quot;requiresApprovingReviews&quot;: false,
              &quot;requiresCodeOwnerReviews&quot;: false,
              &quot;requiresCommitSignatures&quot;: false,
              &quot;requiresConversationResolution&quot;: false,
              &quot;requiresDeployments&quot;: false,
              &quot;requiresLinearHistory&quot;: false,
              &quot;requiresStatusChecks&quot;: false,
              &quot;requiresStrictStatusChecks&quot;: true,
              &quot;restrictsPushes&quot;: false,
              &quot;restrictsReviewDismissals&quot;: false
            }
          }
        ]
      }
    }
  }
}

And with the setting checked:

GitHub GraphQL API – 分支保护规则 – 如何获取“在合并之前需要拉取请求”?

We get:

{
  &quot;data&quot;: {
    &quot;repository&quot;: {
      &quot;branchProtectionRules&quot;: {
        &quot;edges&quot;: [
          {
            &quot;node&quot;: {
              &quot;allowsDeletions&quot;: false,
              &quot;allowsForcePushes&quot;: false,
              &quot;blocksCreations&quot;: false,
              &quot;dismissesStaleReviews&quot;: false,
              &quot;isAdminEnforced&quot;: false,
              &quot;lockAllowsFetchAndMerge&quot;: false,
              &quot;lockBranch&quot;: false,
              &quot;pattern&quot;: &quot;master&quot;,
              &quot;requireLastPushApproval&quot;: false,
              &quot;requiredApprovingReviewCount&quot;: 0,
              &quot;requiredDeploymentEnvironments&quot;: [],
              &quot;requiresApprovingReviews&quot;: true,
              &quot;requiresCodeOwnerReviews&quot;: false,
              &quot;requiresCommitSignatures&quot;: false,
              &quot;requiresConversationResolution&quot;: false,
              &quot;requiresDeployments&quot;: false,
              &quot;requiresLinearHistory&quot;: false,
              &quot;requiresStatusChecks&quot;: false,
              &quot;requiresStrictStatusChecks&quot;: true,
              &quot;restrictsPushes&quot;: false,
              &quot;restrictsReviewDismissals&quot;: false
            }
          }
        ]
      }
    }
  }
}

So the difference is:

GitHub GraphQL API – 分支保护规则 – 如何获取“在合并之前需要拉取请求”?

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.

huangapple
  • 本文由 发表于 2023年6月2日 01:32:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76384359.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定