Graphql: Get repository contributors

I need to get the contributors of the repository using the github api previously in V3 i can able to get this but the calling the followig api

https://developer.github.com/v3/repos/#list-contributors

But now i am migrating to v4. How can i get the list of contributors of the repository?

2 Likes

Hi @parithiban,

Thanks for being here! On v4 you can use the RepositoryCollaboratorConnection:

{
  repository(owner: "andreagriffiths11", name: "graphql-test") {
    collaborators {
      nodes {
        name
      }
    }
  }
}

returns my collaborators for the graphql-test repo:

{
  "data": {
    "repository": {
      "collaborators": {
        "nodes": [
          {
            "name": "Andrea Liliana Griffiths"
          },
          {
            "name": "Krystle Scott"
          },
          {
            "name": "ag1111"
          }
        ]
      }
    }
  }
}

Hey @andreagriffiths11 ,

In my expierence it only works when using the owner’s access token (even for public repos),

that is unlike the v3 api that @parithiban have mentioned.

@andreagriffiths11 

Thanks for the reply. I would like to rephrase my question I already know I can get the collaborators of the repository. But my scenario is that I need to get the top contributors of the repo based on the contributions made. Suppose if you look at the example in https://developer.github.com/v3/repos/#list-contributors. It has a result

[
  {
    "login": "octocat",
    "id": 1,
    "node_id": "MDQ6VXNlcjE=",
    "avatar_url": "https://github.com/images/error/octocat_happy.gif",
    "gravatar_id": "",
    "url": "https://api.github.com/users/octocat",
    "html_url": "https://github.com/octocat",
    "followers_url": "https://api.github.com/users/octocat/followers",
    "following_url": "https://api.github.com/users/octocat/following{/other_user}",
    "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
    "organizations_url": "https://api.github.com/users/octocat/orgs",
    "repos_url": "https://api.github.com/users/octocat/repos",
    "events_url": "https://api.github.com/users/octocat/events{/privacy}",
    "received_events_url": "https://api.github.com/users/octocat/received_events",
    "type": "User",
    "site_admin": false,
    "contributions": 32
  }
]

If you look at the result you can get

"contributions": 32

Now I need to get this specific value.

Whereas I can’t get this via collaborators?

In my scenario I need to loop through those results set from the API and need to find the top contributors of that repo based on contributions count.

1 Like

@andreagriffiths11 
Is there any Github V4 API similar to this https://developer.github.com/v3/repos/#list-contributors. I need to list all the contributors to the repo.

4 Likes

Looks like this still isn’t available for GraphQL API. See this related stackoverflow answer, but I think this is a must-have.

cc @andreagriffiths11 any updates here?

Thanks for the ping @eric-hc, The collaborators field as listed on here https://developer.github.com/v4/object/repository/ in our reference is the only option as of now. There is no way to do this programatically on v4. You can see it on the UI from the insights tab https://github.com/atom/atom/graphs/contributors. Sorry I didn’t have better news.

I would like to vote for this feature to be included in the Graphql API. Thank you @andreagriffiths11!

1 Like

Up !

contributors already exist for the API Rest API, it’s a must have for the GraphQL API :slight_smile: