Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub API: finding number of stars,commits and releases

I'm making an Android app that uses the GitHub API. My goal is to make a list of repositories for a github user.

I've tried using GET /users/:username/repos, but it doesn't return all of the info I need. How can I get all of the repository data for each repository belonging to the user?

like image 331
Yaroslav Romanyuta Avatar asked Oct 21 '25 03:10

Yaroslav Romanyuta


1 Answers

By making requests to /users/:username/repos you get the list of repositories for the specified user but they contain the important fields. This is called Summary Representation.

Stars

The list of repositories contain repository objects containing the stargazers_count which is the number of stars.

Commits count

Get the contributors and sum the commit counts, like described in this answer.

Releases

Use the /repos/:owner/:repo/releases endpoint:

GET /repos/:owner/:repo/releases?per_page=1

Status: 200 OK
Link: <https://api.github.com/resource?page=2>; rel="next",
      <https://api.github.com/resource?page=5>; rel="last"
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999

You can use rel="last" from the the Link header to get the releases count (in this example 5).

By using per_page=1 we limit the number of objects per page to one, so we can just get then the number of pages and know it's the same with the number of releases.

like image 200
Ionică Bizău Avatar answered Oct 24 '25 07:10

Ionică Bizău



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!