sgonzalez
sgonzalez

Reputation: 836

Getting Issues and Pull Requests for a specific user

I'm pulling all issues and pull requests for several organization owned repositories via API based on the name of the repository the user passes in. I want to be able to display all of the issues/pull requests assigned to the user as well as the latest issues and pull requests commented on by the user.

I could do this by pulling all issues/PRs for all the repositories that the user is a member of, then doing some processing to find exactly which are assigned to just the username. The problem is that this doesn't scale very well: If several users request this data within the same time range I will quickly burn through the API rate limit.

I was wondering if there was any way of getting issues/PRs for only specific usernames? Or there any other way of solving this issue that doesn't require getting all issues/PRs for all repos every time. Thanks in advance.

Upvotes: 1

Views: 924

Answers (1)

Bertrand Martel
Bertrand Martel

Reputation: 45372

You can use Github Graphql API v4 to do this with a single request.

The following request will search issues with state:open for a specific repo with a specific user assignee with a specific commenter user who have commented on this issue :

{
  search(first: 100, type: ISSUE, query: "user:CosmicMind repo:material assignee:danieldahan commenter:danieldahan state:open") {
    issueCount
    pageInfo {
      hasNextPage
      endCursor
    }
    edges {
      node {
        ... on Issue {
          createdAt
          title
          url
        }
      }
    }
  }
}

You can test it in the explorer

Upvotes: 1

Related Questions