fix(comments review): 送出前排序 Review comments
This commit is contained in:
+7
-3
@@ -94,11 +94,15 @@ export async function postFindingsReview(findings, deps = {}) {
|
|||||||
summaryFindings = findings,
|
summaryFindings = findings,
|
||||||
commentFindings = findings,
|
commentFindings = findings,
|
||||||
} = deps;
|
} = deps;
|
||||||
const sortedComments = [...commentFindings].sort(bySeverity);
|
const commentItems = commentFindings
|
||||||
const comments = sortedComments.map(toReviewComment).filter(Boolean);
|
.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);
|
const body = buildReviewSummary(summaryFindings);
|
||||||
await postReview({ body, comments });
|
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}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -238,6 +238,22 @@ describe('postFindingsReview', () => {
|
|||||||
assert.equal(reviewCalls[0].comments[0].path, 'app/b.js');
|
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 () => {
|
it('uses an explicit problem field when present', async () => {
|
||||||
const reviewCalls = [];
|
const reviewCalls = [];
|
||||||
await postFindingsReview([
|
await postFindingsReview([
|
||||||
|
|||||||
Reference in New Issue
Block a user