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 <ralavi@redhat.com>
  • Loading branch information
RamLavi committed Jun 26, 2024
1 parent 7c01e87 commit 8ba291b
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 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,21 @@ 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 := 0; pageIdx < maxPagePaginate; pageIdx++ {
branchCommits, _, 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")
}

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

0 comments on commit 8ba291b

Please sign in to comment.