test(comments review): 強化嚴重等級解析 helper
This commit is contained in:
+15
-7
@@ -6,13 +6,6 @@ import path from 'node:path';
|
|||||||
import { saveFindings, parseLocation, postNewCriticalComments, postFindingsReview } from './comments.js';
|
import { saveFindings, parseLocation, postNewCriticalComments, postFindingsReview } from './comments.js';
|
||||||
import { FINDINGS_PATH } from './config.js';
|
import { FINDINGS_PATH } from './config.js';
|
||||||
|
|
||||||
const REVIEW_SEVERITY_PATTERN = /\*\*嚴重等級\*\*:(🔴 嚴重|🟡 警告|🔵 建議)(?:\n|$)/;
|
|
||||||
const REVIEW_SEVERITY_LABELS = ['🔴 嚴重', '🟡 警告', '🔵 建議'];
|
|
||||||
|
|
||||||
function reviewSeverityLabel(comment) {
|
|
||||||
return comment.body.match(REVIEW_SEVERITY_PATTERN)?.[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('saveFindings', () => {
|
describe('saveFindings', () => {
|
||||||
const tempDirs = [];
|
const tempDirs = [];
|
||||||
const makeTempDir = prefix => {
|
const makeTempDir = prefix => {
|
||||||
@@ -194,6 +187,21 @@ describe('postNewCriticalComments', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('postFindingsReview', () => {
|
describe('postFindingsReview', () => {
|
||||||
|
const REVIEW_SEVERITY_LABELS = ['🔴 嚴重', '🟡 警告', '🔵 建議'];
|
||||||
|
const REVIEW_SEVERITY_PATTERN = new RegExp(`\\*\\*嚴重等級\\*\\*:(${REVIEW_SEVERITY_LABELS.join('|')})(?:\\n|$)`);
|
||||||
|
|
||||||
|
function reviewSeverityLabel(comment) {
|
||||||
|
return comment?.body?.match(REVIEW_SEVERITY_PATTERN)?.[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
it('handles missing review severity bodies gracefully', () => {
|
||||||
|
assert.equal(reviewSeverityLabel(null), undefined);
|
||||||
|
assert.equal(reviewSeverityLabel(undefined), undefined);
|
||||||
|
assert.equal(reviewSeverityLabel({}), undefined);
|
||||||
|
assert.equal(reviewSeverityLabel({ body: null }), undefined);
|
||||||
|
assert.equal(reviewSeverityLabel({ body: undefined }), undefined);
|
||||||
|
});
|
||||||
|
|
||||||
it('extracts review severity labels only when the format is valid', () => {
|
it('extracts review severity labels only when the format is valid', () => {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
reviewSeverityLabel({ body: '**嚴重等級**:🔴 嚴重\n**審查員**:Rex' }),
|
reviewSeverityLabel({ body: '**嚴重等級**:🔴 嚴重\n**審查員**:Rex' }),
|
||||||
|
|||||||
Reference in New Issue
Block a user