Skip to content

Commit

Permalink
Paginate through GitHub API branches
Browse files Browse the repository at this point in the history
  • Loading branch information
kochman committed Jul 31, 2017
1 parent f15367f commit 4f73a31
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions travis/client.go
Expand Up @@ -18,14 +18,24 @@ func (t *Client) Branches() ([]Branch, error) {
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: t.GitHubAccessToken})
tc := oauth2.NewClient(context.Background(), ts)
ghc := github.NewClient(tc)
ghb, _, err := ghc.Repositories.ListBranches(context.Background(), t.Org, t.Repo, nil)
if err != nil {
return nil, err
}

branches := make([]Branch, len(ghb))
// loop over all pages in response
ghBranches := []*github.Branch{}
opt := &github.ListOptions{}
for {
ghb, resp, err := ghc.Repositories.ListBranches(context.Background(), t.Org, t.Repo, opt)
if err != nil {
return nil, err
}
ghBranches = append(ghBranches, ghb...)
if resp.NextPage == 0 {
break
}
opt.Page = resp.NextPage
}

for i, branch := range ghb {
branches := make([]Branch, len(ghBranches))
for i, branch := range ghBranches {
cs, _, err := ghc.Repositories.GetCombinedStatus(context.Background(), t.Org, t.Repo, *branch.Name, nil)
if err != nil {
return nil, err
Expand Down

0 comments on commit 4f73a31

Please sign in to comment.