fix(評論發布): 只統計新問題並排序 comments #32
+12
-7
@@ -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}`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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'],
|
||||
|
||||
+5
-1
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user