調整 AI review 以單一 Review 發布統計與 comments #28
+4
-6
@@ -60,18 +60,16 @@ function countBy(findings, predicate) {
|
|||||||
return findings.filter(predicate).length;
|
return findings.filter(predicate).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildReviewSummary(findings, commentable) {
|
function buildReviewSummary(findings) {
|
||||||
const unplacedCount = findings.length - commentable.length;
|
|
||||||
const criticalCount = countBy(findings, f => f.level === 'critical');
|
const criticalCount = countBy(findings, f => f.level === 'critical');
|
||||||
const warningCount = countBy(findings, f => f.level === 'warning');
|
const warningCount = countBy(findings, f => f.level === 'warning');
|
||||||
const infoCount = countBy(findings, f => f.level === 'info');
|
const infoCount = countBy(findings, f => f.level === 'info');
|
||||||
return [
|
return [
|
||||||
'## AI Code Review 統計',
|
'## AI Code Review 統計',
|
||||||
'',
|
'',
|
||||||
'| 統計 | 統計 | 統計 |',
|
'| 🔴 嚴重 | 🟡 警告 | 🔵 建議 |',
|
||||||
'| --- | --- | --- |',
|
'| --- | --- | --- |',
|
||||||
`| **總問題**<br>${findings.length} 筆 | **可標註檔案與行數**<br>${commentable.length} 筆 | **無法標註檔案與行數**<br>${unplacedCount} 筆 |`,
|
`| ${criticalCount} 筆 | ${warningCount} 筆 | ${infoCount} 筆 |`,
|
||||||
`| **🔴 嚴重**<br>${criticalCount} 筆 | **🟡 警告**<br>${warningCount} 筆 | **🔵 建議**<br>${infoCount} 筆 |`,
|
|
||||||
].join('\n');
|
].join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +91,7 @@ export async function postFindingsReview(findings, deps = {}) {
|
|||||||
const { postReview = postPullReview } = deps;
|
const { postReview = postPullReview } = deps;
|
||||||
const sorted = [...findings].sort(bySeverity);
|
const sorted = [...findings].sort(bySeverity);
|
||||||
const comments = sorted.map(toReviewComment).filter(Boolean);
|
const comments = sorted.map(toReviewComment).filter(Boolean);
|
||||||
const body = buildReviewSummary(sorted, comments);
|
const body = buildReviewSummary(sorted);
|
||||||
await postReview({ body, comments });
|
await postReview({ body, comments });
|
||||||
ok(`review 發布: total=${sorted.length} commentable=${comments.length}`);
|
ok(`review 發布: total=${sorted.length} commentable=${comments.length}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,9 +200,8 @@ describe('postFindingsReview', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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, /\| \*\*總問題\*\*<br>3 筆 \| \*\*可標註檔案與行數\*\*<br>3 筆 \| \*\*無法標註檔案與行數\*\*<br>0 筆 \|/);
|
assert.match(reviewCalls[0].body, /\| 1 筆 \| 1 筆 \| 1 筆 \|/);
|
||||||
assert.match(reviewCalls[0].body, /\| \*\*🔴 嚴重\*\*<br>1 筆 \| \*\*🟡 警告\*\*<br>1 筆 \| \*\*🔵 建議\*\*<br>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'],
|
||||||
@@ -227,7 +226,7 @@ describe('postFindingsReview', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(reviewCalls.length, 1);
|
assert.equal(reviewCalls.length, 1);
|
||||||
assert.match(reviewCalls[0].body, /\| \*\*總問題\*\*<br>2 筆 \| \*\*可標註檔案與行數\*\*<br>1 筆 \| \*\*無法標註檔案與行數\*\*<br>1 筆 \|/);
|
assert.match(reviewCalls[0].body, /\| 1 筆 \| 1 筆 \| 0 筆 \|/);
|
||||||
assert.equal(reviewCalls[0].comments.length, 1);
|
assert.equal(reviewCalls[0].comments.length, 1);
|
||||||
assert.equal(reviewCalls[0].comments[0].path, 'app/b.js');
|
assert.equal(reviewCalls[0].comments[0].path, 'app/b.js');
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user