I want to allow the users to signup using github account, and display all his/her private and public repositories. I am able to get the token from github and get the repositories (both public and private), but the only problem is that it is not returning all repositories (i.e. some repositories are not fetched).
I am using golang for server side implementation. Using this method to get repositories.
By default all the commands that accept a ListOptions
argument have a PerPage
attribute. In order to get all the data, you'll have to iterate through the pages using the Page
attribute until the number of results you get is less than PerPage
.
In Go-ish pseudo-code, it'd look like this:
totalResults := []Result{}
for page := 0; ; page++ {
results := fetch current page
totalResults = append(totalResults, results)
if len(results) < per page {
break
}
}
You can see the ListOptions
struct defined here.
As pointed out by robbrit to get all repos we have to use PerPage option, because by default only 30 repos are returned. That solved my problem.