From 279bcc2101618c595901b57b4aa374cb46c8b335 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Mon, 22 Jun 2026 23:02:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=A9=95=E8=AB=96=E7=99=BC=E5=B8=83):=20?= =?UTF-8?q?=E5=8F=AA=E7=B5=B1=E8=A8=88=E6=96=B0=E5=95=8F=E9=A1=8C=E4=B8=A6?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=20comments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/comments.js | 19 ++++++++++++------- app/comments.test.js | 4 +++- app/main.js | 6 +++++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/comments.js b/app/comments.js index 587dc54..c597c6d 100644 --- a/app/comments.js +++ b/app/comments.js @@ -84,16 +84,21 @@ function toReviewComment(f) { } /** - * 發布單一 Gitea review:本文統計可找出檔案與行數的問題, - * comments 只包含可定位到檔案與行數的 findings,並依嚴重等級排序。 + * 發布單一 Gitea review: + * - summaryFindings 只用來統計本文數字 + * - commentFindings 用來產生 review comments,並依嚴重等級排序 */ export async function postFindingsReview(findings, deps = {}) { - const { postReview = postPullReview } = deps; - const sorted = [...findings].sort(bySeverity); - const comments = sorted.map(toReviewComment).filter(Boolean); - const body = buildReviewSummary(sorted); + const { + postReview = postPullReview, + summaryFindings = findings, + commentFindings = findings, + } = deps; + const sortedComments = [...commentFindings].sort(bySeverity); + const comments = sortedComments.map(toReviewComment).filter(Boolean); + const body = buildReviewSummary(summaryFindings); await postReview({ body, comments }); - ok(`review 發布: total=${sorted.length} commentable=${comments.length}`); + ok(`review 發布: summary=${summaryFindings.length} total=${sortedComments.length} commentable=${comments.length}`); } /** diff --git a/app/comments.test.js b/app/comments.test.js index a6de0d8..c0ffab4 100644 --- a/app/comments.test.js +++ b/app/comments.test.js @@ -196,12 +196,14 @@ describe('postFindingsReview', () => { ]; await postFindingsReview(findings, { + summaryFindings: findings.filter(f => f.is_new !== false), + commentFindings: findings, postReview: async (args) => { reviewCalls.push(args); }, }); assert.equal(reviewCalls.length, 1); assert.match(reviewCalls[0].body, /\| 🔴 嚴重 \| 🟡 警告 \| 🔵 建議 \|/); - assert.match(reviewCalls[0].body, /\| 1 筆 \| 1 筆 \| 1 筆 \|/); + assert.match(reviewCalls[0].body, /\| 0 筆 \| 1 筆 \| 1 筆 \|/); assert.deepEqual( reviewCalls[0].comments.map(c => c.path), ['app/a.js', 'app/b.js', 'app/c.js'], diff --git a/app/main.js b/app/main.js index a1d7082..e519818 100644 --- a/app/main.js +++ b/app/main.js @@ -111,7 +111,11 @@ async function main() { const reviewDir = repoDir || WORKSPACE; saveFindings(WORKSPACE, filtered, reviewDir); try { - await postFindingsReview(filtered); + const newFindings = filtered.filter(f => f.is_new !== false); + await postFindingsReview(filtered, { + summaryFindings: newFindings, + commentFindings: filtered, + }); ok('Step6 完成'); } catch (e) { warn(`review 發布失敗(繼續執行): ${e.message}`);