Files
superwork/vscode/src/gitea/markers.ts
T
chehongweo 858bd1e34b 🐛 fix(vscode): 修复 PR 上的审查意见没自动转给实施会话
识别审查评论标记和 PR 里 Closes #N 的规则被写坏(多了反斜杠、标记名少了个 s),
审查评论全被当成普通评论丢掉。现在这两条规则只在 gitea/markers.ts 里定义一份,
webhook 和评论气泡都调用它,并补上单测,以后写坏会直接测出来。
2026-09-29 04:43:55 +08:00

28 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 评论 / PR 正文里约定标记的唯一解析入口。
*
* - 审查标记:审查会话发到 PR 上的评论第一行写 `<!-- spx:review=1 -->`,
* webhook 靠它识别"这是审查意见,要转给实施会话"。
* - 关闭关键字:PR body 里的 `Closes #N` 等,用来从 PR 反查工单号。
*/
const REVIEW_MARKER = /<!--\s*spx:review=1\s*-->/i
// 带 g 的正则只给 replace 用:replace 每次从头扫,不受 lastIndex 残留影响。
const REVIEW_MARKER_WITH_TRAILING_SPACE = new RegExp(`${REVIEW_MARKER.source}\\s*`, 'gi')
const CLOSING_KEYWORD = /\b(?:closes|fixes|resolves|close|fix|resolve)\s+#(\d+)/i
export function hasReviewMarker(body: string): boolean {
return REVIEW_MARKER.test(body)
}
/** 去掉所有审查标记及其后空白,返回 trim 后的正文。 */
export function stripReviewMarker(body: string): string {
return body.replace(REVIEW_MARKER_WITH_TRAILING_SPACE, '').trim()
}
/** 从 PR body 取第一个关闭关键字指向的工单号。 */
export function parseClosingIssueNumber(body: string): number | undefined {
const m = body.match(CLOSING_KEYWORD)
return m ? Number.parseInt(m[1], 10) : undefined
}