Reputation: 801
I am using the following to get the repositories of an organisation.
requests.get('https://api.github.com/orgs/ORG/repos', {'org': 'microsoft', 'per_page': 100})
But for an organisation like Google, there are 1.9k repositories and I want the top 500 repositories with the highest fork. How can I do it ??
P.S:
This
requests.get('https://api.github.com/orgs/ORG/repos', {'org': 'microsoft', 'per_page': 500})
gives only 100 repositories (as the max in 100).
Upvotes: 1
Views: 2727
Reputation: 79
If you have gh
, the github cli (https://cli.github.com/) and jq
(https://stedolan.github.io/jq/) you can do this:
gh repo list $ORG -L $COUNT --json name | jq '.[].name' | tr -d '"'
where $ORG is your organization name and $COUNT is the max number of repos returned
Upvotes: 0
Reputation: 1992
These types of requests are rate limited by Github for a reason. They claim it is expensive for them to make those kinds of large requests. See this link for their reasoning: https://github.community/t/github-api-v3-pagination-limit/14106
However there is a way to get the additional repositories above 100. Let's take a look at the documentation here: Github API v3
The Link header in the response includes pagination information:
Link: https://api.github.com/user/repos?page=3&per_page=100; rel="next",
https://api.github.com/user/repos?page=50&per_page=100; rel="last"
The response header gives you the next page and the last page. You can parse through the response headers to find out how many pages of 100 items exist. Then you can make your additional requests. In the above example there are 50 pages and 100 per page.
The following answer solves the problem using javascript but the code for python would be similar: How to get number of result pages for the data fetched from Github API for a request?
Upvotes: 1