✨ feat(vscode): 工单状态评论改写成隐藏格式,Gitea 和 YouTrack 共用一套读写

This commit is contained in:
cruldra committed 2026-10-19 07:35:55 +11:00
1 parent fa7b32d205
commit 38ca193434
17 files changed
+588 -660

No files matched your search

+6 -38
View File
@@ -7,16 +7,15 @@
*/
import type { ExtensionContext } from 'vscode'
import type { Issue, IssueColumn } from '../gitea/types'
import type { Issue } from '../gitea/types'
import type { YouTrackIssue } from './api'
import { workspace } from 'vscode'
import { getYouTrackToken } from '../auth/secrets'
import { latestState } from '../issues/stateComment'
import { issueStateFields } from '../issues/stateFields'
import { getSettings } from '../settings/store'
import { issueHtmlUrl, listIssues } from './api'
import { readImportedIds } from './importStore'
import { findLatestState } from './stateComment'
const VALID_COLUMNS = new Set<IssueColumn>(['todo', 'in-progress', 'review', 'done'])
/** Host part of the configured base URL — the SecretStorage token key. */
export function youtrackHost(baseUrl: string): string {
@@ -28,10 +27,6 @@ export function youtrackHost(baseUrl: string): string {
}
}
function str(v: unknown): string | undefined {
return typeof v === 'string' && v.length > 0 ? v : undefined
}
/**
* Offset added to a YouTrack issue's numeric id so its board `number` never
* collides with a gitea issue number (which is the routing key for
@@ -47,45 +42,18 @@ function syntheticNumber(idReadable: string): number {
return YOUTRACK_NUMBER_OFFSET + (m ? Number(m[1]) : 0)
}
function pickColumn(rawColumn: unknown, resolved: number | null): IssueColumn {
if (typeof rawColumn === 'string' && VALID_COLUMNS.has(rawColumn as IssueColumn))
return rawColumn as IssueColumn
return resolved != null ? 'done' : 'todo'
}
function toIssue(baseUrl: string, it: YouTrackIssue): Issue {
const state = findLatestState(it.comments) ?? {}
const { column, ...fields } = issueStateFields(latestState(it.comments.map(comment => comment.text)) ?? {})
return {
id: `youtrack:${it.idReadable}`,
externalId: it.idReadable,
source: 'youtrack',
number: syntheticNumber(it.idReadable),
title: it.summary,
column: pickColumn(state.column, it.resolved),
column: column ?? (it.resolved != null ? 'done' : 'todo'),
htmlUrl: issueHtmlUrl(baseUrl, it.idReadable),
attachments: it.attachments,
sessionId: str(state.sessionId),
implementSessionId: str(state.implementSessionId),
reviewSessionId: str(state.reviewSessionId),
testSessionId: str(state.testSessionId),
prototypeSessionId: str(state.prototypeSessionId),
profilePath: str(state.profilePath),
brainstormProfilePath: str(state.brainstormProfilePath),
testProfilePath: str(state.testProfilePath),
prototypeProfilePath: str(state.prototypeProfilePath),
specFile: str(state.specFile),
planFile: str(state.planFile),
prototypeFile: str(state.prototypeFile),
prDiffFile: str(state.prDiffFile),
pr: str(state.pr),
branch: str(state.branch),
worktreePath: str(state.worktreePath),
color: str(state.color),
implementStatus: state.implementStatus === 'running' || state.implementStatus === 'done' || state.implementStatus === 'failed'
? state.implementStatus
: undefined,
autoReview: typeof state.autoReview === 'boolean' ? state.autoReview : undefined,
reviewPassed: typeof state.reviewPassed === 'boolean' ? state.reviewPassed : undefined,
...fields,
}
}