Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 14 additions & 4 deletions dist/nx-set-shas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
33 changes: 24 additions & 9 deletions nx-set-shas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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;
}
Expand Down