🐛 fix(vscode): 移除侵入式弹窗并过滤 PR 评论,仅对工单讨论发送简洁系统通知

This commit is contained in:
cruldra committed 2026-09-29 10:49:28 +08:00
1 parent 8ea5361f3d
commit 6a2ab7eaf4
5 files changed
+172 -24

No files matched your search

+69
View File
@@ -53,3 +53,72 @@ export function systemCommentText(body: string): string | undefined {
return `更新了工单状态,放到${column}`
return '更新了工单状态'
}
/**
* 清洗 Markdown 评论内容并截断为单行纯文本摘要:
* 1. 移除 HTML 注释与代码块
* 2. 移除引用行(> 开头)、表格分割线行、水平分割线
* 3. 移除/转换行内 Markdown(链接、图片、行内代码、粗斜体、删除线、表格符号、标题与列表标记等)
* 4. 坍缩为空格单行,最多保留 maxLength 个字符,超出追加 '...'
*/
export function cleanCommentSummary(body: string, maxLength = 60): string {
if (!body)
return ''
// 移除 HTML 注释和代码块
let text = body
.replace(/<!--[\s\S]*?-->/g, '')
.replace(/```[\s\S]*?```/g, '')
const rawLines = text.split(/\r?\n/)
// 逐行剔除引用行、表格分割线、水平分割线
let lines = rawLines.filter((line) => {
const trimmed = line.trim()
if (!trimmed)
return false
if (trimmed.startsWith('>'))
return false
if (/^[-: |]+$/.test(trimmed) && trimmed.includes('-'))
return false
if (/^[-*_]{3,}$/.test(trimmed))
return false
return true
})
// 若全是引用行,回退保留去掉 > 后的行
if (lines.length === 0) {
lines = rawLines
.map(line => line.trim().replace(/^>+\s*/, ''))
.filter(Boolean)
}
text = lines.join(' ')
// 移除图片 ![alt](url)
.replace(/!\[.*?\]\(.*?\)/g, '')
// 链接 [text](url) -> text
.replace(/\[(.*?)\]\(.*?\)/g, '$1')
// 自动链接 <http...> 与纯标签
.replace(/<https?:\/\/[^>]+>/g, '')
.replace(/<[^>]+>/g, '')
// 行内代码 `code` -> code
.replace(/`([^`]+)`/g, '$1')
// 粗体、斜体、删除线
.replace(/(\*\*|__)(.*?)\1/g, '$2')
.replace(/(\*|_)(.*?)\1/g, '$2')
.replace(/~~(.*?)~~/g, '$1')
// 任务列表 [- [x] / - [ ]]
.replace(/\[[ x]\]\s+/gi, '')
// 标题、无序列表、有序列表前缀
.replace(/(^|\s)(?:#{1,6}|[*+-])\s+/g, '$1')
.replace(/(^|\s)\d+\.\s+/g, '$1')
// 表格竖线符号
.replace(/\|/g, ' ')
// 坍缩连续空白字符为单空格
const singleLine = text.replace(/\s+/g, ' ').trim()
if (singleLine.length <= maxLength)
return singleLine
return `${singleLine.slice(0, maxLength)}...`
}