✨ feat(vscode): 看板底栏新增工单讨论 Tab 并支持系统气泡与 Gitea 评论同步
This commit is contained in:
1 parent
8ecb40b330
commit
df17821408
14 files changed
+1555
-2
No files matched your search
@@ -44,6 +44,12 @@ export interface GiteaComment {
|
||||
issue_url: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
user?: {
|
||||
id: number
|
||||
login: string
|
||||
full_name?: string
|
||||
avatar_url?: string
|
||||
}
|
||||
}
|
||||
|
||||
export class GiteaApiError extends Error {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { systemCommentText } from './issueComment'
|
||||
|
||||
describe('systemCommentText', () => {
|
||||
it('列评论变成一句系统话', () => {
|
||||
expect(systemCommentText('{"column":"todo"}')).toBe('把工单放到待办')
|
||||
})
|
||||
|
||||
it('带别的状态字段时仍只说列', () => {
|
||||
expect(systemCommentText('{"column":"review","color":"terminal.ansiBlue"}')).toBe('更新了工单状态,放到审查')
|
||||
})
|
||||
|
||||
it('普通评论不是系统消息', () => {
|
||||
expect(systemCommentText('这个方案可以')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('审查评论去掉标记,剩下的正文当系统消息', () => {
|
||||
expect(systemCommentText('<!-- spx:review=1 -->\n看过了')).toBe('看过了')
|
||||
expect(systemCommentText('<!-- spx:review=1 -->')).toBe('提交了审查')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,53 @@
|
||||
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 '更新了工单状态'
|
||||
}
|
||||
Reference in new issue
Block a user