Downgoat
Downgoat

Reputation: 14361

How to obtain solely issues from GitHub's API

GitHub has the following API to obtain the "issues" from a repository:

GET /repos/:owner/:repo/issues

Ok, good right? If you look carefully you'll notice this section:

"pull_request": {
  "url": "https://api.github.com/repos/cheddar-lang/Cheddar/pulls/76",
  "html_url": "https://github.com/cheddar-lang/Cheddar/pull/76",
  "diff_url": "https://github.com/cheddar-lang/Cheddar/pull/76.diff",
  "patch_url": "https://github.com/cheddar-lang/Cheddar/pull/76.patch"
}

this means it's a pull request.

I have done additional testing and it appears that Pull Requests are returned with this API call.


I understand GitHub internally considers both Issues and Pull Requests as one of the same, but is there anyway to get only, Issues (excluding Pull Requests)?

I know I can filter issues on the client side. However if a repository has a much higher ratio of Pull Requests compared to issues, I don't want to make a ridiculous amount of API requests, to do this.

Upvotes: 4

Views: 199

Answers (1)

Wilhelm Klopp
Wilhelm Klopp

Reputation: 5440

You should be able to do this with the GraphQL API

In fact, the point of the GraphQL API is to only specify exactly what you want.

So you can have a query like this:

{
  repository(owner: ":owner", name: ":repo") {
    id
    issues(first: 100) {
      edges {
        node {
          id
          number
          title
          url
        }
      }
    }
  }
}

That will return the first 100 issues for a specific repository, and only include the id, number, title, and url for each issue.

Useful links:
Repository documentation: https://developer.github.com/early-access/graphql/object/repository/

Issue documentation: https://developer.github.com/early-access/graphql/object/issue/

Upvotes: 2

Related Questions