Skip to content

Commit b67ef0d

Browse files
committed
Add total count and pagination info for commits
1 parent 389b8f4 commit b67ef0d

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

.github/workflows/check-signature.yaml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ jobs:
3737
repository(owner: $owner, name: $repo) {
3838
pullRequest(number: $pr) {
3939
commits(first: 100) {
40+
totalCount
41+
pageInfo {
42+
hasNextPage
43+
}
4044
nodes {
4145
commit {
4246
oid
@@ -58,7 +62,14 @@ jobs:
5862
};
5963
6064
const result = await github.graphql(query, variables);
61-
const commits = result.repository.pullRequest.commits.nodes;
65+
const commitsConnection = result.repository.pullRequest.commits;
66+
const commits = commitsConnection.nodes;
67+
68+
// Fail closed if PR exceeds max single-page limits (100 commits)
69+
if (commitsConnection.pageInfo.hasNextPage || commitsConnection.totalCount > 100) {
70+
core.setFailed(`PR block: Pull Request contains too many commits (${commitsConnection.totalCount}). Maximum supported limit for a automated verification run is 100 commits.`);
71+
return;
72+
}
6273
6374
// 2. Identify unsigned or validation-failing commits
6475
const unsignedCommits = commits.filter(c => !c.commit.signature || !c.commit.signature.isValid);
@@ -68,14 +79,15 @@ jobs:
6879
owner: context.repo.owner,
6980
repo: context.repo.repo,
7081
issue_number: prNumber,
82+
per_page: 100
7183
});
7284
7385
const existingComment = comments.data.find(c => c.body.includes(commentIdentifier));
7486
7587
// 4. Handle logic based on validation state
7688
if (unsignedCommits.length > 0) {
7789
const commitList = unsignedCommits.map(c => `- \`${c.commit.oid.substring(0, 7)}\``).join('\n');
78-
const commentBody = `${commentIdentifier}\n.⚠️ **Unsigned Commits Detected**\n\nThe following commits in this Pull Request are missing a verified cryptographic signature:\n\n${commitList}\n\nPlease sign your commits to comply with <a href="https://metoffice.github.io/simulation-systems/WorkingPractices/gh_authorisation.html#verified-commits">project guidelines</a>.`;
90+
const commentBody = `${commentIdentifier}\n ⚠️ **Unsigned Commits Detected**\n\nThe following commits in this Pull Request are missing a verified cryptographic signature:\n\n${commitList}\n\nPlease sign your commits to comply with <a href="https://metoffice.github.io/simulation-systems/WorkingPractices/gh_authorisation.html#verified-commits">project guidelines</a>.`;
7991
8092
if (existingComment) {
8193
// Update the old comment with the refreshed list of unsigned commits
@@ -96,7 +108,8 @@ jobs:
96108
}
97109
98110
// Force the CI status check to fail outright
99-
core.setFailed("❌ PR block: One or more commits do not have a verified signature.");
111+
core.setFailed("PR block: One or more commits do not have a verified signature.");
112+
return;
100113
101114
} else {
102115
// All commits are signed! Clear old warning comment if it exists
@@ -108,5 +121,5 @@ jobs:
108121
});
109122
console.log("::notice::Clean state achieved: Deleted the old signature warning comment.");
110123
}
111-
console.log("::success::All commits are properly signed.");
124+
console.log("::notice::All commits are properly signed.");
112125
}

0 commit comments

Comments
 (0)