Skip to content

Commit 98f88de

Browse files
author
Jeremy Udit
authored
Merge pull request integrations#366 from shoekstra/repository_file__add_list_commit_pagination
Handle pagination when listing commits in github_repository_file
2 parents 8c9a8c3 + 35fb459 commit 98f88de

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

github/resource_github_repository_file.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,26 @@ func checkRepositoryFileExists(client *github.Client, org, repo, file, branch st
320320

321321
func getFileCommit(client *github.Client, org, repo, file, branch string) (*github.RepositoryCommit, error) {
322322
ctx := context.WithValue(context.Background(), ctxId, fmt.Sprintf("%s/%s", repo, file))
323-
commits, _, err := client.Repositories.ListCommits(ctx, org, repo, &github.CommitsListOptions{SHA: branch})
324-
if err != nil {
325-
return nil, err
323+
opts := &github.CommitsListOptions{
324+
SHA: branch,
325+
}
326+
allCommits := []*github.RepositoryCommit{}
327+
for {
328+
commits, resp, err := client.Repositories.ListCommits(ctx, org, repo, opts)
329+
if err != nil {
330+
return nil, err
331+
}
332+
333+
allCommits = append(allCommits, commits...)
334+
335+
if resp.NextPage == 0 {
336+
break
337+
}
338+
339+
opts.Page = resp.NextPage
326340
}
327341

328-
for _, c := range commits {
342+
for _, c := range allCommits {
329343
sha := c.GetSHA()
330344

331345
// Skip merge commits

0 commit comments

Comments
 (0)