Skip to content

Commit

Permalink
add pagination to GetCommit() call (#2009)
Browse files Browse the repository at this point in the history
Signed-off-by: Rumen Vasilev <git@rumenvasilev.com>
Co-authored-by: Keegan Campbell <me@kfcampbell.com>
  • Loading branch information
rumenvasilev and kfcampbell authored Nov 13, 2023
1 parent 6b7fd8b commit f184099
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions github/repository_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,27 @@ func getFileCommit(client *github.Client, owner, repo, file, branch string) (*gi
continue
}

rc, _, err := client.Repositories.GetCommit(ctx, owner, repo, sha, nil)
if err != nil {
return nil, err
opts := &github.ListOptions{}
allFiles := []*github.CommitFile{}
var rc *github.RepositoryCommit
var resp *github.Response
var err error
for {
rc, resp, err = client.Repositories.GetCommit(ctx, owner, repo, sha, opts)
if err != nil {
return nil, err
}

allFiles = append(allFiles, rc.Files...)

if resp.NextPage == 0 {
break
}

opts.Page = resp.NextPage
}

for _, f := range rc.Files {
for _, f := range allFiles {
if f.GetFilename() == file && f.GetStatus() != "removed" {
return rc, nil
}
Expand Down

0 comments on commit f184099

Please sign in to comment.