Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query the top contributors to a GitHub repository using GraphQL

Using GitHub's GraphQL API (v4), how do I query for the top contributors of a given repository? I have a list of repositories and I'd like to display some relevant data for each repository–namely, the top 5 contributors (based on commits) for each repository in the list.

Here is my current query:

{
  organization(login: "the-road-to-learn-react") {
    id
    repositories(first: 20) {
      edges {
        node {
          collaborators(affiliation: ALL) {
            edges {
              node {
                name
              }
            }
          }
        }
      }
    }
  }
}

I'm running into the error: "Must have push access to view repository collaborators". My thought is to get all of the collaborators for each repository, then query each of those users for the number of contributions made to the repository. How can this be done? Is there a way to do this without querying for repository collaborators?

like image 573
Britt Shroyer Avatar asked Nov 16 '22 13:11

Britt Shroyer


1 Answers

In order to access the repository collaborators list through the API you have to be one of the collaborators in the project.

You can read more about Permission levels for a user account repository.

And even if you are one of the collaborators, the organization might have not have OAuth App access to some of the repositories.

You can read more about Restricting access to your organization's data.

So I believe that query can't be done unless the above requirements are met.

like image 174
Marco Daniel Avatar answered Dec 05 '22 18:12

Marco Daniel