54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
const COLUMN_LABEL: Record<string, string> = {
|
|
'todo': '待办',
|
|
'in-progress': '进行中',
|
|
'review': '审查',
|
|
'done': '完成',
|
|
}
|
|
|
|
const STATE_KEYS = new Set([
|
|
'column',
|
|
'sessionId',
|
|
'implementSessionId',
|
|
'reviewSessionId',
|
|
'testSessionId',
|
|
'prototypeSessionId',
|
|
'handoffAttachmentId',
|
|
'handoffFrom',
|
|
'handoffRequestFrom',
|
|
'handoffRequestError',
|
|
'pr',
|
|
'branch',
|
|
'worktreePath',
|
|
'color',
|
|
'autoReview',
|
|
])
|
|
|
|
/** 插件自己写的评论。返回系统气泡文案;普通讨论返回 undefined。 */
|
|
export function systemCommentText(body: string): string | undefined {
|
|
const trimmed = body.trim()
|
|
if (/<!--\s*spx:review=1\s*-->/i.test(trimmed)) {
|
|
const text = trimmed.replace(/<!--\s*spx:review=1\s*-->/gi, '').trim()
|
|
return text.length > 0 ? text : '提交了审查'
|
|
}
|
|
if (!trimmed.startsWith('{'))
|
|
return undefined
|
|
let parsed: unknown
|
|
try {
|
|
parsed = JSON.parse(trimmed)
|
|
}
|
|
catch {
|
|
return undefined
|
|
}
|
|
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
return undefined
|
|
const record = parsed as Record<string, unknown>
|
|
if (!Object.keys(record).some(key => STATE_KEYS.has(key)))
|
|
return undefined
|
|
const column = typeof record.column === 'string' ? COLUMN_LABEL[record.column] : undefined
|
|
if (Object.keys(record).length === 1 && column)
|
|
return `把工单放到${column}`
|
|
if (column)
|
|
return `更新了工单状态,放到${column}`
|
|
return '更新了工单状态'
|
|
}
|