7

I want to query using GitHub Graphql api for project contributors, can anyone give me any hints how to make it? Just been trying for some time, and I guess that I am missing some small element.

I'd like to get sth like https://api.github.com/repos/facebook/react/contributors?page=15 but only for amount of conttributions

Greetings!

Piotr Kaliński
  • 227
  • 1
  • 4
  • 13

3 Answers3

2

updated: May, 2020.

Github GraphQL API currently don't support getting contributors of a repo.

You can get the collaborators though....

query {
  repository(owner: "peek", name: "peek") {
    id
    name

    collaborators(first: 10, affiliation: ALL) {
      edges {
        permission
        node {
          id
          login
          name
        }
      }
    }
  }

  rateLimit {
    cost
  }
}

You need to have push rights to the repository to view the collaborators.

sreenivas
  • 2,067
  • 1
  • 19
  • 29
  • 18
    This is collaborators, not contributors. You can not (as of April 2018) get the v3 API equivalent to `/repos/$USER/$REPO/contributors` through the GraphQL API. – Michael Cramer Apr 20 '18 at 15:05
  • This is not the solution. collaborators shows more then I expect. On the webpage I see only 2 collaborators for a given repository whereas the api returns many more. – Marco Mar 31 '20 at 15:08
  • I updated the answer to reflect the status Thanks Michael & Marco – sreenivas May 01 '20 at 01:38
2

The Github graphql v4 API does not seem to support contributor nodes unless you have push access to a repo.

I get this error when i try to get a list of a repo's collaborators

"errors": [
{
  "message": "Must have push access to view repository collaborators.",
  "type": "FORBIDDEN",
Fatah
  • 2,184
  • 4
  • 18
  • 39
1

The closest match to get the equivalent of v3 REST API url /repos/$USER/$REPO/contributors i could find is:

query {
  repository(owner: "peek", name: "peek") {
    id
    name
    mentionableUsers {
      totalCount
    }
  }
}

It seems to count all contributors in a repository that could be matched to Github users (most probable through their emails).

ecp
  • 2,199
  • 1
  • 12
  • 11
  • All users who watch the repo are counted as mentionableUsers. So this list can be 1-3 orders of magnitude larger than real contributors. – Ivan Kleshnin Dec 23 '22 at 07:34
  • I did some metadata collection just recently and you are right, the mentionable users are not the same as the number of contributors as can be seen on the repo landing page. However in most cases the reported number is smaller than the watchers count, so it's something different (the list seems to be populated by various actions of users like being part in discussions etc.) – ecp Jan 02 '23 at 10:25
  • Yes, thank you for clarification. It's a shame it's not documented what "mentionableUsers" actually are. According to my new exploration this category consists primarily of: 1. Owners (users with a permission to push, even if never commited) 2. Some contributors (unclear by which criteria) Not sure about other metrics. – Ivan Kleshnin Jan 03 '23 at 11:04