From a5a4de1ed493386d643409695f85e1608d4c9483 Mon Sep 17 00:00:00 2001 From: Ram Lavi Date: Wed, 26 Jun 2024 13:50:35 +0300 Subject: [PATCH] bumper: Paginate over commits on tagged update policy 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 --- tools/bumper/component_commands.go | 27 ++++++++++++++++++--------- tools/bumper/git_fakes.go | 2 +- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/tools/bumper/component_commands.go b/tools/bumper/component_commands.go index 2c27bc828..9c2b06619 100644 --- a/tools/bumper/component_commands.go +++ b/tools/bumper/component_commands.go @@ -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] @@ -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 diff --git a/tools/bumper/git_fakes.go b/tools/bumper/git_fakes.go index a2b05d94e..4c25d6382 100644 --- a/tools/bumper/git_fakes.go +++ b/tools/bumper/git_fakes.go @@ -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) {