diff --git a/action.yml b/action.yml index 68e0186..ada9259 100644 --- a/action.yml +++ b/action.yml @@ -32,6 +32,9 @@ inputs: use-previous-merge-group-commit: description: 'When using merge-group, use the previous commit in the group as the base SHA' default: 'true' + commit-pagination-limit: + description: 'When searching for the last successful workflow run on the main branch, this is the maximum number of pages of commits to check (each page is 100 commits). Increase this value if you have a lot of commits between workflow runs on your main branch. Note: each page requires an API call, so increasing this value may lead to hitting GitHub API rate limits.' + default: '20' outputs: base: diff --git a/dist/nx-set-shas.js b/dist/nx-set-shas.js index f3f6f6a..8ea367e 100644 --- a/dist/nx-set-shas.js +++ b/dist/nx-set-shas.js @@ -3435,7 +3435,7 @@ var require_constants2 = __commonJS((exports, module) => { } })(); var channel; - var structuredClone = globalThis.structuredClone ?? function structuredClone(value, options = undefined) { + var structuredClone = globalThis.structuredClone ?? function structuredClone2(value, options = undefined) { if (arguments.length === 0) { throw new TypeError("missing argument"); } @@ -22715,6 +22715,7 @@ var fallbackSHA = core.getInput("fallback-sha"); var remote = core.getInput("remote"); var usePreviousMergeGroupCommit = core.getBooleanInput("use-previous-merge-group-commit"); var defaultWorkingDirectory = "."; +var maxCommitPages = core.getInput("commit-pagination-limit"); var BASE_SHA; (async () => { if (workingDirectory !== defaultWorkingDirectory) { @@ -22868,13 +22869,22 @@ async function commitExists(octokit, branchName, commitSha) { repo, commit_sha: commitSha }); - const commits = await octokit.request("GET /repos/{owner}/{repo}/commits", { + let maxPages = maxCommitPages; + for await (const response of octokit.paginate.iterator("GET /repos/{owner}/{repo}/commits", { owner, repo, sha: branchName, per_page: 100 - }); - return commits.data.some((commit) => commit.sha === commitSha); + })) { + if (response.data.some((commit) => commit.sha === commitSha)) { + return true; + } + maxPages--; + if (maxPages <= 1) { + break; + } + } + return false; } catch { return false; } diff --git a/nx-set-shas.ts b/nx-set-shas.ts index bf3dc77..93d9254 100644 --- a/nx-set-shas.ts +++ b/nx-set-shas.ts @@ -23,6 +23,7 @@ const usePreviousMergeGroupCommit = core.getBooleanInput( 'use-previous-merge-group-commit', ); const defaultWorkingDirectory = '.'; +const maxCommitPages = core.getInput('commit-pagination-limit'); let BASE_SHA: string; (async () => { @@ -259,16 +260,30 @@ async function commitExists( }); // Check the commit exists on the expected main branch (it will not in the case of a rebased main branch) - const commits = await octokit.request('GET /repos/{owner}/{repo}/commits', { - owner, - repo, - sha: branchName, - per_page: 100, - }); + let maxPages = maxCommitPages; + for await (const response of octokit.paginate.iterator( + 'GET /repos/{owner}/{repo}/commits', + { + owner, + repo, + sha: branchName, + per_page: 100, + }, + )) { + if ( + response.data.some( + (commit: { sha: string }) => commit.sha === commitSha, + ) + ) { + return true; + } + maxPages--; + if (maxPages <= 1) { + break; + } + } - return commits.data.some( - (commit: { sha: string }) => commit.sha === commitSha, - ); + return false; } catch { return false; }