GraphQL API response for commit status is null

Using the GraphQL API Explorer (but also in my own code), and with the following query:

query($owner:String!,$name:String!) {
  repository(owner:$owner,name:$name) {
    pullRequests(last:10, states:OPEN) {
      nodes {
        commits(last:1) {
          nodes {
            commit {
              status {
                state
              }
            }
          }
        }
      }
    }
  }
}

The commit status is always null for private repositories, even though the GraphQL API Explorer has the right access, and some of the first pull requests do return a status.

Am I using the wrong query to get the commit status of the last commit for a given PR, or is something else wrong?

Hey @pascaldevink!

Your query looks right to me! I tested it in a couple of my private repositories and it returned the data that I expected. In your code, are you using a Personal Access Token (PAT)? If so, what scopes does it have? 

Hi @nickvanw, thanks for coming back to me.

I’m currently using a personal access token with all the repo access, and read:org, although I want to eventually migrate to using OAuth.

I think I’ve tracked down the root issue: For some repositories, I was able to get all the status information on commits, but for some repositories I was only able to do that up till a certain point.

We are using CircleCI in our organisation and in October we’ve switched to using Pull Request Checks. You can probably already guess when the status field stopped giving usefull information by now.

I see the checks API is still in beta, but the announcement and documentation only cover V3 of the API. Is there an equivalent in V4? And is there any documentation on it for V4?

Hey @pascaldevink!

I think the GraphQL API may be able to do what you want! There is a Commit.checkSuites connection that should get you the names and statuses of CircleCI’s Checks, something like this:

query ($owner: String!, $name: String!) {
  repository(owner: $owner, name: $name) {
    pullRequests(last: 10, states: OPEN) {
      nodes {
        commits(last: 1) {
          nodes {
            commit {
              checkSuites(first: 10) {
                nodes {
                  app {
                    name
                  }
                  checkRuns(first:10) {
                    nodes {
                      status
                      name
                    }
                  }
                  status
                }
              }
            }
          }
        }
      }
    }
  }
}

Let me know if that works!

1 Like

@nickvanw wrote:

Hey @pascaldevink!

 

Your query looks right to me! I tested it in a couple of my private repositories and it returned the data that I expected. In your code, are you using a Personal Access Token (PAT)? If so, what scopes does it have? 

@nickvanwI am seeing a similar issue, I can see status for private and public repos with no branch protection rules, however, on repos with branch protection rules on I only get null for all status checks in the Graphql API.

@starefossen hit the same exact issue in a repo with branch protection rules. Were you able to find anything?

Hello @sfpetersen, thanks for joining us!

If you can share the query you’re using, that will generally help people diagnose the problem you’re encountering much, much easier. So if you can share your query, that would be very helpful.

The specific query I was using is below, though I’m sure I could reproduce it without the associatedPullRequests bit. Thanks!

{
  repository(owner: "my-organization", name: "my-repo") {
    object(oid: "667589986fac336663fc89dce53f9c993e9bfafe") {
      ... on Commit {
        associatedPullRequests(first: 10) {
          nodes { 
            number 
            state
            title
            mergeable
            reviewDecision
            commits(last: 1){
              nodes{
                commit{
                  commitUrl
                  oid
                  statusCheckRollup {
                    state
                  }
                  status {
                    id
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Interestingly, the “statusCheckRollup” field seems to work fine - but the “status” field is always null.

In this specific case, what I’m really looking for is a way to get the result of the “Require branches to be up to date before merging” check. I’m not actually sure if that is broken out in the status field.

I was unable to reproduce the problem you’re describing. I used the query:

{
  repository(owner: "atom", name: "atom") {
    object(oid: "4a9d56f52cab00a22744858d4077600d5365197a") {
      ... on Commit {
        associatedPullRequests(first: 10) {
          nodes { 
            number 
            state
            title
            mergeable
            reviewDecision
            commits(last: 1){
              nodes{
                commit{
                  commitUrl
                  oid
                  statusCheckRollup {
                    state
                  }
                  status {
                    id
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

and saw SUCCESS in the statusCheckRollup.state field.

That sounds like a separate question from this entirely. Would you mind opening a new topic for specifically this question @sfpetersen?

OK yes I will open a new topic when I get a chance. To be clear, I also get SUCCESS in the statusCheckRollup.state field, but the status field is null. It’s my understanding that status should have more details regarding the individual status checks.

@lee-dohm I opened a separate topic for the other question: API query to get result of "Require branches to be up to date before merging" branch protection check for a Pull Request. Thanks!

1 Like