Skip to content

Commit 0237597

Browse files
committed
fix: address remaining CodeRabbit feedback
- Fix CHANGELOG.md merge conflict markers - Fix truncation count mismatch in comment (shows 'at least N' when truncated) Signed-off-by: cheese-cakee <farzanaman99@gmail.com>
1 parent d15fa71 commit 0237597

File tree

1 file changed

+43
-12
lines changed

1 file changed

+43
-12
lines changed

.github/scripts/bot-verified-commits.js

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,24 +145,36 @@ async function hasExistingBotComment(github, owner, repo, prNumber) {
145145
}
146146

147147
// Builds the verification failure comment with unverified commit details
148-
function buildVerificationComment(commitsUrl, unverifiedCommits = []) {
148+
function buildVerificationComment(
149+
commitsUrl,
150+
unverifiedCommits = [],
151+
unverifiedCount = unverifiedCommits.length,
152+
truncated = false
153+
) {
149154
// Build list of unverified commits (show first 10 max)
150155
const maxDisplay = 10;
151-
const commitList = unverifiedCommits.slice(0, maxDisplay).map(c => {
152-
const sha = c.sha?.substring(0, 7) || 'unknown';
153-
const msg = sanitizeString(c.commit?.message?.split('\n')[0] || 'No message').substring(0, 50);
154-
return `- \`${sha}\` ${msg}`;
155-
}).join('\n');
156+
const commitList = unverifiedCommits.length
157+
? unverifiedCommits.slice(0, maxDisplay).map(c => {
158+
const sha = c.sha?.substring(0, 7) || 'unknown';
159+
const msg = sanitizeString(c.commit?.message?.split('\n')[0] || 'No message').substring(0, 50);
160+
return `- \`${sha}\` ${msg}`;
161+
}).join('\n')
162+
: (truncated ? '- Unable to enumerate commits due to pagination limit.' : '');
156163

157164
const moreCommits = unverifiedCommits.length > maxDisplay
158165
? `\n- ...and ${unverifiedCommits.length - maxDisplay} more`
159166
: '';
160167

168+
const countText = truncated ? `at least ${unverifiedCount}` : `${unverifiedCount}`;
169+
const truncationNote = truncated
170+
? '\n\n> ⚠️ Verification scanned only the first pages of commits due to pagination limits. Please review the commits tab.'
171+
: '';
172+
161173
return `${CONFIG.COMMENT_MARKER}
162174
Hi, this is ${CONFIG.BOT_NAME}.
163-
Your pull request cannot be merged as it has **${unverifiedCommits.length} unverified commit(s)**:
175+
Your pull request cannot be merged as it has **${countText} unverified commit(s)**:
164176
165-
${commitList}${moreCommits}
177+
${commitList}${moreCommits}${truncationNote}
166178
167179
View your commit verification status: [Commits Tab](${sanitizeString(commitsUrl)}).
168180
@@ -180,15 +192,24 @@ From the ${CONFIG.TEAM_NAME}`;
180192
}
181193

182194
// Posts verification failure comment on the PR with error handling
183-
async function postVerificationComment(github, owner, repo, prNumber, commitsUrl, unverifiedCommits) {
195+
async function postVerificationComment(
196+
github,
197+
owner,
198+
repo,
199+
prNumber,
200+
commitsUrl,
201+
unverifiedCommits,
202+
unverifiedCount,
203+
truncated
204+
) {
184205
console.log(`[${CONFIG.BOT_NAME}] Posting verification failure comment...`);
185206

186207
try {
187208
await github.rest.issues.createComment({
188209
owner,
189210
repo,
190211
issue_number: prNumber,
191-
body: buildVerificationComment(commitsUrl, unverifiedCommits),
212+
body: buildVerificationComment(commitsUrl, unverifiedCommits, unverifiedCount, truncated),
192213
});
193214
console.log(`[${CONFIG.BOT_NAME}] Comment posted on PR #${prNumber}`);
194215
return true;
@@ -226,7 +247,8 @@ async function main({ github, context }) {
226247

227248
try {
228249
// Get commit verification status
229-
const { total, unverified, unverifiedCommits } = await getCommitVerificationStatus(github, owner, repo, prNumber);
250+
const { total, unverified, unverifiedCommits, truncated } =
251+
await getCommitVerificationStatus(github, owner, repo, prNumber);
230252

231253
// All commits verified - success
232254
if (unverified === 0) {
@@ -244,7 +266,16 @@ async function main({ github, context }) {
244266
console.log(`[${CONFIG.BOT_NAME}] Bot already commented. Skipping duplicate.`);
245267
} else {
246268
const commitsUrl = `https://github.com/${owner}/${repo}/pull/${prNumber}/commits`;
247-
await postVerificationComment(github, owner, repo, prNumber, commitsUrl, unverifiedCommits);
269+
await postVerificationComment(
270+
github,
271+
owner,
272+
repo,
273+
prNumber,
274+
commitsUrl,
275+
unverifiedCommits,
276+
unverified,
277+
truncated
278+
);
248279
}
249280

250281
return { success: false, unverifiedCount: unverified };

0 commit comments

Comments
 (0)