Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the number of forks of a GitHub repo with the GitHub API?

I use Github API V3 to get forks count for a repository, i use:

GET /repos/:owner/:repo/forks

The request bring me only 30 results even if a repository contain more, I googled a little and I found that due to the memory restrict the API return only 30 results per page, and if I want next results I have to specify the number of page.

Only me I don't need all this information, all I need is the number of forks.
Is there any way to get only the number of forks?

Because If I start to loop page per page my script risque to crash if a repository contain thousand results.

like image 679
medkhelifi Avatar asked Jan 07 '23 09:01

medkhelifi


1 Answers

You can try and use a search query.

For instance, for my repo VonC/b2d, I would use:

https://api.github.com/search/repositories?q=user%3AVonC+repo%3Ab2d+b2d

The json answer gives me a "forks_count": 5

Here is one with more than 4000 forks (consider only the first result, meaning the one whose "full_name" is actually "strongloop/express")

https://api.github.com/search/repositories?q=user%3Astrongloop+repo%3Aexpress+express

"forks_count": 4114,
like image 69
VonC Avatar answered Mar 08 '23 23:03

VonC