Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commit not found if more than 100 commits on a branch #144

Open
TonyWhiteSMS opened this issue Mar 7, 2024 · 2 comments
Open

Commit not found if more than 100 commits on a branch #144

TonyWhiteSMS opened this issue Mar 7, 2024 · 2 comments
Labels
feature New feature or request

Comments

@TonyWhiteSMS
Copy link

When a large number of commits have been made to a branch (eg more 200) it fails to verify that the commitExists on the branch.

I believe that this code is not finding the commit due the number of commits being limited to 100

            // Check the commit exists on the expected main branch (it will not in the case of a rebased main branch)
            const commits = yield octokit.request("GET /repos/{owner}/{repo}/commits", {
                owner,
                repo,
                sha: branchName,
                per_page: 100,
            });
            return commits.data.some((commit) => commit.sha === commitSha);

Obviously going back to the start of the repo could be expensive, so perhaps a customisable limit of commits/pages could be allowed. In my instance I am currently looking at a pull req with 940+ commits for an upcoming release.

@TonyWhiteSMS
Copy link
Author

I have come up with a solution that should work for us, it is hard coded to a 20 page (2K commit limit)

           // Check the commit exists on the expected main branch (it will not in the case of a rebased main branch)
            let maxPages = 20;
            let commitFound = false;
            yield octokit.paginate("GET /repos/{owner}/{repo}/commits", {
                owner,
                repo,
                sha: branchName,
                per_page: 100,
            }, (response, done) => {
                if (response.data.some((commit) => commit.sha === commitSha)) {
                    commitFound = true;
                    done();
                }
                // End after maxPages reached
                if (maxPages <= 0) {
                    done();
                }
                maxPages--;
                return response;
            });
            return commitFound;

@mandarini
Copy link
Member

Hi there @TonyWhiteSMS ! Thank you for the feature request and the suggested implementation! Do you want to submit a PR, and I can review it? Thank you for your patience!

@mandarini mandarini added the feature New feature or request label Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants