Skip to content

Commit c7af7a9

Browse files
authored
Merge pull request #170 from google/fix/integration-workflow-commit-validation
fix: integration tests workflow for SHA validation
2 parents 15d0ad4 + 8e69374 commit c7af7a9

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

.github/workflows/integration_test.yml

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,40 @@ jobs:
5555
// Get PR number from the issue
5656
const prNumber = context.payload.issue.number;
5757
58-
// Get list of commits in the PR
59-
const { data: commits } = await github.rest.pulls.listCommits({
60-
owner: context.repo.owner,
61-
repo: context.repo.repo,
62-
pull_number: prNumber
63-
});
58+
// Normalize SHA to lowercase for comparison
59+
const normalizedSha = sha.toLowerCase();
60+
61+
// Get all commits from the PR with pagination
62+
const commits = [];
63+
let page = 1;
64+
let hasMore = true;
65+
66+
while (hasMore) {
67+
const { data: pageCommits } = await github.rest.pulls.listCommits({
68+
owner: context.repo.owner,
69+
repo: context.repo.repo,
70+
pull_number: prNumber,
71+
per_page: 100,
72+
page: page
73+
});
74+
75+
commits.push(...pageCommits);
76+
hasMore = pageCommits.length === 100;
77+
page++;
78+
}
79+
80+
console.log(`Total commits in PR #${prNumber}: ${commits.length}`);
6481
6582
// Check if the provided SHA exists in this PR's commits
66-
const commitExists = commits.some(commit => commit.sha === sha);
83+
const commitExists = commits.some(commit => commit.sha.toLowerCase() === normalizedSha);
6784
6885
if (commitExists) {
6986
console.log(`Verified SHA ${sha} belongs to PR #${prNumber}`);
7087
core.setOutput('has_sha', 'true');
71-
return sha; // Return the SHA directly as the result
88+
return normalizedSha;
7289
} else {
7390
console.log(`Error: SHA ${sha} does not belong to PR #${prNumber}`);
91+
console.log(`Total commits checked: ${commits.length}`);
7492
console.log('The SHA must be from a commit in the current PR.');
7593
core.setOutput('has_sha', 'false');
7694
return ''; // Return empty string if SHA not in PR

0 commit comments

Comments
 (0)