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
12 changes: 12 additions & 0 deletions .changeset/silver-hawks-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"layne": patch
---

fix(server): confirmation comment only says "Re-running scan..." when a scan is actually queued

The issue_comment handler only re-enqueues a scan when the latest check
run conclusion is 'failure'. However the confirmation comment always
ended with "Re-running scan..." regardless of whether a scan was queued.
Users who approved an exception while the check run was in a success or
neutral state (or when no check run existed) saw a misleading message.
The suffix is now conditional on the scan actually being enqueued.
33 changes: 33 additions & 0 deletions src/__tests__/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,39 @@ describe('issue_comment handler', () => {
expect(scanQueue.add).not.toHaveBeenCalled();
});

it('confirmation comment says "Re-running scan..." when check run is in failure state', async () => {
(getLatestCheckRun as ReturnType<typeof vi.fn>).mockResolvedValue({ conclusion: 'failure' });

await processWebhookRequest(webhookRequest(
commentPayload(), { event: 'issue_comment' }
));

const [call] = (createPrComment as ReturnType<typeof vi.fn>).mock.calls as [{ body: string }][];
expect(call[0].body).toContain('Re-running scan');
});

it('confirmation comment does NOT say "Re-running scan..." when check run did not fail', async () => {
(getLatestCheckRun as ReturnType<typeof vi.fn>).mockResolvedValue({ conclusion: 'success' });

await processWebhookRequest(webhookRequest(
commentPayload(), { event: 'issue_comment' }
));

const [call] = (createPrComment as ReturnType<typeof vi.fn>).mock.calls as [{ body: string }][];
expect(call[0].body).not.toContain('Re-running scan');
});

it('confirmation comment does NOT say "Re-running scan..." when there is no check run', async () => {
(getLatestCheckRun as ReturnType<typeof vi.fn>).mockResolvedValue(null);

await processWebhookRequest(webhookRequest(
commentPayload(), { event: 'issue_comment' }
));

const [call] = (createPrComment as ReturnType<typeof vi.fn>).mock.calls as [{ body: string }][];
expect(call[0].body).not.toContain('Re-running scan');
});

it('does not store exceptions or enqueue scan when PR is already merged', async () => {
(getPullRequest as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
state: 'closed',
Expand Down
6 changes: 4 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ async function handleIssueComment(payload: Record<string, unknown>): Promise<{ s
});

const checkRunData = checkRun as { conclusion?: string } | null;
let scanEnqueued = false;
if (checkRunData?.conclusion === 'failure') {
const jobId = getJobId(repo.full_name, issueData.number, headSha);
await enqueueScan({
Expand All @@ -276,16 +277,17 @@ async function handleIssueComment(payload: Record<string, unknown>): Promise<{ s
jobId,
action: 'issue_comment',
triggeredByException: true,
}).catch(err => console.error(`[server] Failed to enqueue scan: ${(err as Error).message}`));
}).then(() => { scanEnqueued = true; }).catch(err => console.error(`[server] Failed to enqueue scan: ${(err as Error).message}`));
}

const idList = parsed.ids.join(', ');
const confirmationSuffix = scanEnqueued ? ' Re-running scan...' : '';
await createPrComment({
installationId: (installation as { id: number }).id,
owner: repo.owner.login,
repo: repo.name,
prNumber: issueData.number,
body: `✅ Exception recorded for ${idList} by @${commenter}: "${parsed.reason}". Re-running scan...`,
body: `✅ Exception recorded for ${idList} by @${commenter}: "${parsed.reason}".${confirmationSuffix}`,
}).catch(err => console.error(`[server] Failed to post confirmation: ${(err as Error).message}`));

return { status: 200, body: 'Accepted' };
Expand Down
Loading