API Github list contributors

Hi everyone,

I’m currently working with the GitHub API and i think there is a problem (or the mistake is mine but i don’t know where)

I tried to know the number of contributors for a specific repository thanks to this endpoint :

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

Work well on small repository but seems to be wrong on bigger repository

For example, let’s take the repository twbs/bootstrap

On the github page, it display 1007 contributors

If i try this one : https://api.github.com/repos/twbs/bootstrap/contributors?per_page=1&page=900

I want the 900th contributors. But nothing appeared. Actually, it work below the page 381, but then, up to 381, nothing appear. Like if there is only 381 contributors

So at first i tought the problem was with anonymous contributors. So i tried to add them like this :

https://api.github.com/repos/twbs/bootstrap/contributors?per_page=1&page=900&anon=true

(I added the query anon and set it to true)

And it worked. And actually it worked too much because, if i try to have the 1100th contributors like this:

https://api.github.com/repos/twbs/bootstrap/contributors?per_page=1&page=1100&anon=true

API return me a response with someone but the github page display 1007 contributors.

Am i doing something wrong ?

Thanks for help!

1 Like

No, you’re not doing anything wrong. As it states in the documentation:

To improve performance, only the first 500 author email addresses in the repository link to GitHub users. The rest will appear as anonymous contributors without associated GitHub user information.

Therefore, on larger repos, you may not be able to replicate the exact figure that we show on the website.

3 Likes

Thank you for your answer lee-dohm

I read this sentence in the documentation but i don’t care about GitHub user information so i tought it will work anyway with anonymous contributors

But i don’t understand, if i count anonymous contributors, why do i have more contributors than show on the GitHub page ? Who has the correct number ? The API or the GitHub page ?

The GitHub page has the correct number.

Here’s why the API might give a higher number than you expect:

  1. If the repository has more than 500 contributors (for example 501, 500 associated with GitHub information and 1 by definition anonymous)
  2. One or more of the least active contributors made commits with more than one email address (for example 2 different email addresses)

Using the example numbers, the GitHub page would read as 501 contributors but you would see 502 records.

Got it!

Thank you for your explanations !

1 Like

Hi, I have the same problem. The GitHub page shows 834 contributors.
I am trying to get this number using API. API shows that repo has 1002 contributors.

https://api.github.com/repos/apple/swift/contributors?page=1002&per_page=1&anon=true

I have listed all contributors and removed duplicates by “name”. After that, the list still has 910 contributors. Why do I still have more than 834 contributors?

Could you please give me an idea of how can I get the exact number on the GitHub page?

I would be thankful if you explain who is Anonymous user. I didn’t understand why some users are anonymous. As far as I know, the first 500 contributors are linked with the corresponding user, and others are anonymous. Why anonymous users exist before the 500th contributor? For example, the 350th contributor is anonymous
https://api.github.com/repos/apple/swift/contributors?page=350&per_page=1&anon=true
Thanks in advance.

A user can be “anonymous” if there is no GitHub user associated with a given email address. And the reason that your number still may not match the one given by the UI is because the same GitHub user may have contributed using multiple email addresses. This is why I said above:

on larger repos, you may not be able to replicate the exact figure that we show on the website.

The API simply doesn’t return the information you need in order to be able to replicate the number we show.

Thanks for the explaination :smile:

1 Like