Skip to content

Commit

Permalink
bumper: Paginate over commits on tagged update policy
Browse files Browse the repository at this point in the history
Currently on tagged update policy, the bumper looks for the first 100
commits to match the tag.
On Multus the commits are not in this range anymore.
Increase the search range to 1000 commits, using pagination.

Signed-off-by: Ram Lavi <[email protected]>
  • Loading branch information
RamLavi committed Jun 27, 2024
1 parent 7c01e87 commit a5a4de1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
27 changes: 18 additions & 9 deletions tools/bumper/component_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,10 @@ func (componentOps *gitComponent) getLatestTaggedFromBranch(repo, owner, branch,
return "", "", errors.Wrap(err, "Failed to get release tag refs from github client API")
}

branchCommits, _, err := componentOps.githubInterface.listCommits(owner, repo, &github.CommitsListOptions{ListOptions: github.ListOptions{PerPage: 100}, SHA: branch})
if err != nil {
return "", "", errors.Wrap(err, "Failed to get release tag refs from github client API")
}

const (
maxPagePaginate = 10
pageSize = 100
)
// look for the first tag that belongs to the chosen branch, going over from last tag
for i := len(tagRefs) - 1; i >= 0; i-- {
tag := tagRefs[i]
Expand All @@ -216,14 +215,24 @@ func (componentOps *gitComponent) getLatestTaggedFromBranch(repo, owner, branch,
return "", "", errors.Wrap(err, "Failed to get commit-sha from tag name")
}

for _, commit := range branchCommits {
if commit.GetSHA() == commitShaOfTag {
return tagName, commit.GetSHA(), nil
for pageIdx := 1; pageIdx <= maxPagePaginate; pageIdx++ {
branchCommits, resp, err := componentOps.githubInterface.listCommits(owner, repo, &github.CommitsListOptions{ListOptions: github.ListOptions{PerPage: pageSize, Page: pageIdx}, SHA: branch})
if err != nil {
return "", "", errors.Wrap(err, "Failed to get release tag refs from github client API")
}
if resp.NextPage == 0 {
break
}

for _, commit := range branchCommits {
if commit.GetSHA() == commitShaOfTag {
return tagName, commit.GetSHA(), nil
}
}
}
}

return "", "", fmt.Errorf("Error: tag not found in branch %s\n tagRefs=\n%v\nbranchCommits=\n%v\n", branch, tagRefs, branchCommits)
return "", "", fmt.Errorf("Error: tag not found in branch %s on last %d commits\n", branch, maxPagePaginate*pageSize)
}

// getLatestFromBranch get the latest HEAD commit-sha under a given branch, using "latest" Update policy
Expand Down
2 changes: 1 addition & 1 deletion tools/bumper/git_fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (g mockGithubApi) listCommits(owner, repo string, opts *github.CommitsListO
return nil, nil, errors.Wrap(err, "failed performing mock git log")
}

return convertLogToRepositoryCommitList(gitCommitObjList), nil, nil
return convertLogToRepositoryCommitList(gitCommitObjList), &github.Response{NextPage: 1}, nil
}

func (g mockGithubApi) getBranchRef(owner string, repo string, ref string) (*github.Reference, *github.Response, error) {
Expand Down

0 comments on commit a5a4de1

Please sign in to comment.