branchProtectionRules->pushAllowances->actor is empty

I’m running GHE 3.1.1 internally, and I’m looking to use graphQL to pull up a list of all the protected branches and who are the authorized pushers (if any). When I get to the “actor” node, I’m getting empty brackets “{}” for each of them.

I saw the answer in How to read wildcard branch protection rules using the API? which gave me the ability to pull up some sample values, but I can’t see how to get the actual actor allowed to push to the branch.

Here’s a redacted sample:

{
  "data": {
    "repository": {
      "branchProtectionRules": {
        "nodes": [
          {
            "pattern": "foo/bar",
            "isAdminEnforced": true,
            "requiresApprovingReviews": false,
            "pushAllowances": {
              "edges": [
                {
                  "node": {
                    "actor": {},
                    "id": "<long-goofy-hash-thing>"
                  }
                },
                {
                  "node": {
                    "actor": {},
                    "id": "<long-goofy-hash-thing>"
                  }
                },
                {
                  "node": {
                    "actor": {},
                    "id": "<long-goofy-hash-thing>"
                  }
                }
              ]
            }
          },

Is there a way to turn all those "long-goofy-hash-thing"s into actual user names of the actors?

Finally, is there a way to filter the branchProtectionRules by those that have pushAllowances versus just the “first: 100” or “last: …”? – we have several hundred rules.

Hi @rfagen-zoox,

Good to see you around.

I have a very similar issue where I’m trying to get and set the requiredApprovingReviewCount which I was able to manage with the v3 REST API, but only for real branches and not for patterns.

I think in this case we have to get the nodes ID and re-run a node query against said ID, then we can run an ‘update’ query. How to craft such queries … I’m still trying to figure that part out.

I’m new to GraphQL so I have limited Knowledge here. I use GraphiQL to experiment with the queries and the gql python library to implement the actual code.

I’ve found some information here:
https://graphql.braintreepayments.com/guides/node_query/

For example this query works:

query {
  node(id:"Base64IDfromPreviousQuery") {
    ... on BranchProtectionRule {
    id, pattern, requiredApprovingReviewCount
    }
  }
}

Oh Hi Stephane! Nice to see you around as well. I did hear back from GH support with some pointers on getting what I wanted. The key was that because “actor” is a union of types, I needed to include snippets for what to do for each of the types I was interested in:

          pushAllowances(first: 100) {
            edges {
              node {
                actor {
                  __typename
                  ... on User {
                    login
                    id
                  }
                  ... on Team {
                    name
                    id
                  }
                  ... on App {
                    name
                    id
                  }
                }

Then it came down to cribbing some python for fetching all the 100-at-a-time pages, and I got the data I needed. I’m also using graphiql to poke at the schema and python to actually fetch stuff and do things.

I’d gotten as far as seeing autocomplete suggest the __typename but didn’t make it as far as parsing all the different types in the union.