mirror of
https://github.com/samsonjs/retrogit.git
synced 2026-04-27 15:07:43 +00:00
Handle pagination when fetching the organization repositories.
This commit is contained in:
parent
71ebf98ce7
commit
45364c385a
1 changed files with 37 additions and 13 deletions
50
app/repos.go
50
app/repos.go
|
|
@ -216,17 +216,20 @@ type OrgRepos struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRepos(c appengine.Context, githubClient *github.Client, account *Account, user *github.User) (*Repos, error) {
|
func getRepos(c appengine.Context, githubClient *github.Client, account *Account, user *github.User) (*Repos, error) {
|
||||||
// The username parameter must be left blank so that we can get all of the
|
|
||||||
// repositories the user has access to, not just ones that they own.
|
|
||||||
clientUserRepos := make([]github.Repository, 0)
|
clientUserRepos := make([]github.Repository, 0)
|
||||||
page := 1
|
page := 1
|
||||||
for {
|
for {
|
||||||
pageClientUserRepos, response, err := githubClient.Repositories.List("", &github.RepositoryListOptions{
|
pageClientUserRepos, response, err := githubClient.Repositories.List(
|
||||||
ListOptions: github.ListOptions{
|
// The username parameter must be left blank so that we can get all
|
||||||
Page: page,
|
// of the repositories the user has access to, not just ones that
|
||||||
PerPage: 100,
|
// they own.
|
||||||
},
|
"",
|
||||||
})
|
&github.RepositoryListOptions{
|
||||||
|
ListOptions: github.ListOptions{
|
||||||
|
Page: page,
|
||||||
|
PerPage: 100,
|
||||||
|
},
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -264,7 +267,13 @@ func getRepos(c appengine.Context, githubClient *github.Client, account *Account
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
orgs, _, err := githubClient.Organizations.List("", nil)
|
orgs, _, err := githubClient.Organizations.List(
|
||||||
|
"",
|
||||||
|
&github.ListOptions{
|
||||||
|
// Don't bother with pagination for the organization list, the user
|
||||||
|
// is unlikely to have that many.
|
||||||
|
PerPage: 100,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -272,11 +281,26 @@ func getRepos(c appengine.Context, githubClient *github.Client, account *Account
|
||||||
repos.OrgRepos = make([]*OrgRepos, 0, len(orgs))
|
repos.OrgRepos = make([]*OrgRepos, 0, len(orgs))
|
||||||
for i := range orgs {
|
for i := range orgs {
|
||||||
org := &orgs[i]
|
org := &orgs[i]
|
||||||
clientOrgRepos, _, err := githubClient.Repositories.ListByOrg(*org.Login, nil)
|
clientOrgRepos := make([]github.Repository, 0)
|
||||||
if err != nil {
|
page := 1
|
||||||
return nil, err
|
for {
|
||||||
|
pageClientOrgRepos, response, err := githubClient.Repositories.ListByOrg(
|
||||||
|
*org.Login,
|
||||||
|
&github.RepositoryListByOrgOptions{
|
||||||
|
ListOptions: github.ListOptions{
|
||||||
|
Page: page,
|
||||||
|
PerPage: 100,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
clientOrgRepos = append(clientOrgRepos, pageClientOrgRepos...)
|
||||||
|
if response.NextPage == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
page = response.NextPage
|
||||||
}
|
}
|
||||||
|
|
||||||
orgRepos := make([]*Repo, 0, len(clientOrgRepos))
|
orgRepos := make([]*Repo, 0, len(clientOrgRepos))
|
||||||
allRepoCount += len(clientOrgRepos)
|
allRepoCount += len(clientOrgRepos)
|
||||||
for j := range clientOrgRepos {
|
for j := range clientOrgRepos {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue