fix(評論發布): 只統計新問題並排序 comments
This commit is contained in:
+12
-7
@@ -84,16 +84,21 @@ function toReviewComment(f) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 發布單一 Gitea review:本文統計可找出檔案與行數的問題,
|
* 發布單一 Gitea review:
|
||||||
* comments 只包含可定位到檔案與行數的 findings,並依嚴重等級排序。
|
* - summaryFindings 只用來統計本文數字
|
||||||
|
* - commentFindings 用來產生 review comments,並依嚴重等級排序
|
||||||
*/
|
*/
|
||||||
export async function postFindingsReview(findings, deps = {}) {
|
export async function postFindingsReview(findings, deps = {}) {
|
||||||
const { postReview = postPullReview } = deps;
|
const {
|
||||||
const sorted = [...findings].sort(bySeverity);
|
postReview = postPullReview,
|
||||||
const comments = sorted.map(toReviewComment).filter(Boolean);
|
summaryFindings = findings,
|
||||||
const body = buildReviewSummary(sorted);
|
commentFindings = findings,
|
||||||
|
} = deps;
|
||||||
|
const sortedComments = [...commentFindings].sort(bySeverity);
|
||||||
|
const comments = sortedComments.map(toReviewComment).filter(Boolean);
|
||||||
|
const body = buildReviewSummary(summaryFindings);
|
||||||
await postReview({ body, comments });
|
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, {
|
await postFindingsReview(findings, {
|
||||||
|
summaryFindings: findings.filter(f => f.is_new !== false),
|
||||||
|
commentFindings: findings,
|
||||||
postReview: async (args) => { reviewCalls.push(args); },
|
postReview: async (args) => { reviewCalls.push(args); },
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(reviewCalls.length, 1);
|
assert.equal(reviewCalls.length, 1);
|
||||||
assert.match(reviewCalls[0].body, /\| 🔴 嚴重 \| 🟡 警告 \| 🔵 建議 \|/);
|
assert.match(reviewCalls[0].body, /\| 🔴 嚴重 \| 🟡 警告 \| 🔵 建議 \|/);
|
||||||
assert.match(reviewCalls[0].body, /\| 1 筆 \| 1 筆 \| 1 筆 \|/);
|
assert.match(reviewCalls[0].body, /\| 0 筆 \| 1 筆 \| 1 筆 \|/);
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
reviewCalls[0].comments.map(c => c.path),
|
reviewCalls[0].comments.map(c => c.path),
|
||||||
['app/a.js', 'app/b.js', 'app/c.js'],
|
['app/a.js', 'app/b.js', 'app/c.js'],
|
||||||
|
|||||||
+5
-1
@@ -111,7 +111,11 @@ async function main() {
|
|||||||
const reviewDir = repoDir || WORKSPACE;
|
const reviewDir = repoDir || WORKSPACE;
|
||||||
saveFindings(WORKSPACE, filtered, reviewDir);
|
saveFindings(WORKSPACE, filtered, reviewDir);
|
||||||
try {
|
try {
|
||||||
await postFindingsReview(filtered);
|
const newFindings = filtered.filter(f => f.is_new !== false);
|
||||||
|
await postFindingsReview(filtered, {
|
||||||
|
summaryFindings: newFindings,
|
||||||
|
commentFindings: filtered,
|
||||||
|
});
|
||||||
ok('Step6 完成');
|
ok('Step6 完成');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
warn(`review 發布失敗(繼續執行): ${e.message}`);
|
warn(`review 發布失敗(繼續執行): ${e.message}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user