From 297e75cdd577fd4c7cdef99ff4b2d48503a2dd1e Mon Sep 17 00:00:00 2001 From: Jeffery Date: Mon, 22 Jun 2026 16:24:55 +0000 Subject: [PATCH] =?UTF-8?q?fix(comments=20review):=20=E9=80=81=E5=87=BA?= =?UTF-8?q?=E5=89=8D=E6=8E=92=E5=BA=8F=20Review=20comments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/comments.js | 10 +++++++--- app/comments.test.js | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/comments.js b/app/comments.js index c597c6d..63a5d19 100644 --- a/app/comments.js +++ b/app/comments.js @@ -94,11 +94,15 @@ export async function postFindingsReview(findings, deps = {}) { summaryFindings = findings, commentFindings = findings, } = deps; - const sortedComments = [...commentFindings].sort(bySeverity); - const comments = sortedComments.map(toReviewComment).filter(Boolean); + const commentItems = commentFindings + .map(finding => ({ finding, comment: toReviewComment(finding) })) + .filter(item => item.comment); + const comments = commentItems + .sort((a, b) => bySeverity(a.finding, b.finding)) + .map(item => item.comment); const body = buildReviewSummary(summaryFindings); await postReview({ body, comments }); - ok(`review 發布: summary=${summaryFindings.length} total=${sortedComments.length} commentable=${comments.length}`); + ok(`review 發布: summary=${summaryFindings.length} total=${commentFindings.length} commentable=${comments.length}`); } /** diff --git a/app/comments.test.js b/app/comments.test.js index f413765..8dabaa3 100644 --- a/app/comments.test.js +++ b/app/comments.test.js @@ -238,6 +238,22 @@ describe('postFindingsReview', () => { assert.equal(reviewCalls[0].comments[0].path, 'app/b.js'); }); + it('sorts the final review comment payload after filtering non-commentable findings', async () => { + const reviewCalls = []; + await postFindingsReview([ + { level: 'info', role: 'Maya', location: 'app/c.js:30', suggestion: 'I' }, + { level: 'critical', role: 'Rex', location: 'app/a.js', suggestion: 'missing line' }, + { level: 'warning', role: 'Leo', location: 'app/b.js:20', suggestion: 'W' }, + ], { + postReview: async (args) => { reviewCalls.push(args); }, + }); + + assert.deepEqual( + reviewCalls[0].comments.map(c => c.body.match(/嚴重等級\*\*:(.+)/)?.[1]), + ['🟡 警告', '🔵 建議'], + ); + }); + it('uses an explicit problem field when present', async () => { const reviewCalls = []; await postFindingsReview([