How to get changes for a pull request


#1

I’m new to GraphQL and spent some time trying to figure this out on my own, but so far I find it very hard to understand how to compile the query for what I need. The auto-completes are nice if you know what you are doing, but if you don’t, then the v3 API was at least quite simple to go through until you found the right endpoint.

I’m trying to load a list of pull requests with their respective changes, ideally filter by a branch name prefix. Is there a way to do that with GraphQL?


#2

Hey @gr2m!

I’m sorry to hear you’re having trouble getting started with our GraphQL API - this is feedback that we hear often, and something that we want to improve. In the long run, we’re hoping that the documentation around our GraphQL setup will be so good that it’s easier to get started compared to v3! Unfortunately, REST got a bit of a head start, and we’re still playing some catch-up on the GraphQL side.

Regarding the question here, I think our GraphQL API is in a place to answer some of those questions, but maybe not all of them.

If you’re looking at an individual Repository, you can use pullRequests (a PullRequestConnection) to get a list of Pull Requests for that repository. That connection allows you to filter by certain things, such as states, labels and headRefName / baseRefName.

Once you get to the list of PullRequest objects, you can get various fields: https://developer.github.com/v4/reference/object/pullrequest/ and connections to commits and other data.

You can also use the GitHub Search via GraphQL, which allows you to use the same search criteria that you would use on github.com. Documentation for that can be found under the search connection here: https://developer.github.com/v4/reference/query/. This may allow you more fine-grained filtering by branch name and other factors.

I hope this has been at least a bit helpful! If there’s anything in particular that I missed, please follow up and I or somebody else will do our best to help. If you find anything missing in the various objects I’ve linked to, let me know and I’ll record it as an official schema request.


#3

Thanks @nickvanw.

This is what I got so far

{
  repository(owner: "hoodiehq", name: "hoodie") {
    pullRequests(first: 100, states: OPEN) {
      edges {
        node {
          title
          headRefName
          commits (first:100) {
            totalCount
            edges {
              node {
                commit {
                  message
                }
              }
            }
          }
        }
      }
    }
  }
}

Is there a way to get file changes for a PR or at least for each commit?


#4

I was looking at this today too and couldn’t figure out how to get to the individual PR changes. Seems like an API limitation?


#5

Yes, that’s correct. We don’t yet support pull request changes in the GraphQL API. There has been a schema request for that here.


#6

Is there rest API for it as a workaround?