From 8272166fdef95e7a169d7b85672a142c1b385db0 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Thu, 25 Jun 2026 15:26:09 +0000 Subject: [PATCH] =?UTF-8?q?fix(review=20publish):=20=E9=99=8D=E7=B4=9A?= =?UTF-8?q?=E8=99=95=E7=90=86=20Gitea=20review=20=E6=89=B9=E6=AC=A1?= =?UTF-8?q?=E7=99=BC=E5=B8=83=E5=A4=B1=E6=95=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/comments.js | 21 ++++++++++++++++++++- app/comments.test.js | 26 ++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/app/comments.js b/app/comments.js index a6acfe2..6755752 100644 --- a/app/comments.js +++ b/app/comments.js @@ -116,6 +116,8 @@ function toReviewComment(f) { export async function postFindingsReview(findings, deps = {}) { const { postReview = postPullReview, + postInline = postPullReviewComment, + postIssue = postComment, summaryFindings = findings, commentFindings = findings, usageSection = '', @@ -123,7 +125,24 @@ export async function postFindingsReview(findings, deps = {}) { const sortedComments = [...commentFindings].sort(bySeverity); const comments = sortedComments.filter(f => f.is_new !== false).map(toReviewComment).filter(Boolean); const body = buildReviewSummary(summaryFindings, usageSection); - await postReview({ body, comments }); + try { + await postReview({ body, comments }); + } catch (e) { + warn(`整批 review 發布失敗,改用 summary + 逐筆行內 comment: ${e.message}`); + try { + await postReview({ body, comments: [] }); + } catch (summaryErr) { + warn(`review summary 發布失敗,改用一般 comment: ${summaryErr.message}`); + await postIssue(body); + } + for (const comment of comments) { + try { + await postInline({ path: comment.path, line: comment.new_position, body: comment.body }); + } catch (commentErr) { + warn(`行內 review comment 發布失敗(略過): ${comment.path}:${comment.new_position} error=${commentErr.message}`); + } + } + } ok(`review 發布: summary=${summaryFindings.length} total=${sortedComments.length} commentable=${comments.length}`); line(`review summary 統計: ${formatFindingsStatsLine(summaryFindings)}`); line(`review comments 統計: ${formatFindingsStatsLine(sortedComments)}`); diff --git a/app/comments.test.js b/app/comments.test.js index 08991bc..7d26416 100644 --- a/app/comments.test.js +++ b/app/comments.test.js @@ -393,4 +393,30 @@ describe('postFindingsReview', () => { assert.match(reviewCalls[0].comments[0].body, /問題.*這裡缺少空值檢查/s); assert.doesNotMatch(reviewCalls[0].comments[0].body, /問題.*app\/a\.js:5/s); }); + + it('falls back to summary review and per-comment posting when batch review fails', async () => { + const reviewCalls = []; + const inlineCalls = []; + await postFindingsReview([ + { level: 'warning', role: 'Leo', location: 'app/a.js:5', suggestion: '修正 A', is_new: true }, + { level: 'info', role: 'Maya', location: 'app/b.js:9', suggestion: '修正 B', is_new: true }, + ], { + postReview: async (args) => { + reviewCalls.push(args); + if (args.comments.length > 0) throw new Error('Request failed with status code 500'); + }, + postInline: async (args) => { + inlineCalls.push(args); + if (args.path === 'app/b.js') throw new Error('line not in diff'); + }, + postIssue: async () => { + throw new Error('一般 comment 不應被呼叫'); + }, + }); + + assert.equal(reviewCalls.length, 2); + assert.equal(reviewCalls[0].comments.length, 2); + assert.equal(reviewCalls[1].comments.length, 0); + assert.deepEqual(inlineCalls.map(c => `${c.path}:${c.line}`), ['app/a.js:5', 'app/b.js:9']); + }); }); -- 2.53.0