11
This commit is contained in:
@@ -13,7 +13,7 @@ import { buildCcCommand } from '../../cc/ccCommand'
|
||||
import { getBrainstormPrompt } from '../../cc/prompts'
|
||||
import { projectsDirFor, watchForNewSession } from '../../cc/sessionWatcher'
|
||||
import { spawnClaude } from '../../cc/spawnClaude'
|
||||
import { gitFetch } from '../../git/branchSync'
|
||||
import { gitFetch, resolveFeatureBranch } from '../../git/branchSync'
|
||||
import { detectRepo } from '../../git/remote'
|
||||
import {
|
||||
addDependency,
|
||||
@@ -22,7 +22,6 @@ import {
|
||||
deleteIssue,
|
||||
getPullRequest,
|
||||
GiteaApiError,
|
||||
listIssueComments,
|
||||
mergePullRequest,
|
||||
removeDependency,
|
||||
} from '../../gitea/api'
|
||||
@@ -101,51 +100,37 @@ export async function handleColumnChange(panel: KanbanWebviewPanel, issueNumber:
|
||||
return
|
||||
}
|
||||
|
||||
// 1. Re-fetch latest state JSON for this issue.
|
||||
// 1. 读最新 state JSON(从尾往前找已知字段,避免普通评论盖住 branch)。
|
||||
let prStr: string | undefined
|
||||
let worktreePath: string | undefined
|
||||
let fromColumn: IssueColumn | undefined
|
||||
let implementSessionId: string | undefined
|
||||
let testSessionId: string | undefined
|
||||
let featureBranch: string | undefined
|
||||
let featureBranchFromState: string | undefined
|
||||
try {
|
||||
const comments = await listIssueComments({
|
||||
const stateObj = await readStateJsonComment({
|
||||
host: remote.host,
|
||||
token,
|
||||
owner: remote.owner,
|
||||
repo: remote.repo,
|
||||
index: issueNumber,
|
||||
issueNumber,
|
||||
})
|
||||
if (comments.length > 0) {
|
||||
const lastBody = (comments[comments.length - 1].body ?? '').trim()
|
||||
if (lastBody) {
|
||||
try {
|
||||
const parsed = JSON.parse(lastBody) as unknown
|
||||
if (parsed && typeof parsed === 'object') {
|
||||
const obj = parsed as Record<string, unknown>
|
||||
if (typeof obj.pr === 'string' && obj.pr.length > 0)
|
||||
prStr = obj.pr
|
||||
if (typeof obj.worktreePath === 'string' && obj.worktreePath.length > 0)
|
||||
worktreePath = obj.worktreePath
|
||||
if (
|
||||
typeof obj.column === 'string'
|
||||
&& ['todo', 'in-progress', 'review', 'done'].includes(obj.column)
|
||||
) {
|
||||
fromColumn = obj.column as IssueColumn
|
||||
}
|
||||
if (typeof obj.implementSessionId === 'string' && obj.implementSessionId.length > 0)
|
||||
implementSessionId = obj.implementSessionId
|
||||
if (typeof obj.testSessionId === 'string' && obj.testSessionId.length > 0)
|
||||
testSessionId = obj.testSessionId
|
||||
if (typeof obj.branch === 'string' && obj.branch.length > 0)
|
||||
featureBranch = obj.branch
|
||||
}
|
||||
}
|
||||
catch {
|
||||
// Non-JSON last comment; leave both undefined.
|
||||
}
|
||||
}
|
||||
if (typeof stateObj.pr === 'string' && stateObj.pr.length > 0)
|
||||
prStr = stateObj.pr
|
||||
if (typeof stateObj.worktreePath === 'string' && stateObj.worktreePath.length > 0)
|
||||
worktreePath = stateObj.worktreePath
|
||||
if (
|
||||
typeof stateObj.column === 'string'
|
||||
&& ['todo', 'in-progress', 'review', 'done'].includes(stateObj.column)
|
||||
) {
|
||||
fromColumn = stateObj.column as IssueColumn
|
||||
}
|
||||
if (typeof stateObj.implementSessionId === 'string' && stateObj.implementSessionId.length > 0)
|
||||
implementSessionId = stateObj.implementSessionId
|
||||
if (typeof stateObj.testSessionId === 'string' && stateObj.testSessionId.length > 0)
|
||||
testSessionId = stateObj.testSessionId
|
||||
if (typeof stateObj.branch === 'string' && stateObj.branch.length > 0)
|
||||
featureBranchFromState = stateObj.branch
|
||||
}
|
||||
catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err)
|
||||
@@ -329,14 +314,18 @@ export async function handleColumnChange(panel: KanbanWebviewPanel, issueNumber:
|
||||
message: `合并 PR #${prIndex} 失败 (issue #${issueNumber})${isConflict ? ' [冲突]' : ''}`,
|
||||
details: message,
|
||||
})
|
||||
if (isConflict && featureBranch && worktreePath) {
|
||||
const conflictBranch = resolveFeatureBranch({
|
||||
stateBranch: featureBranchFromState,
|
||||
prHeadRef: pullRequest.headRef,
|
||||
})
|
||||
if (isConflict && conflictBranch && worktreePath) {
|
||||
// 走冲突解决分支:直接在实施 worktree 里 merge dev 制造冲突落地,
|
||||
// 再开一个临时 cc 会话让 cc 解决。fire-and-forget,不进任何 map / state JSON。
|
||||
await sessions.startConflictResolution(panel, {
|
||||
issueNumber,
|
||||
prIndex,
|
||||
workspaceRoot,
|
||||
featureBranch,
|
||||
featureBranch: conflictBranch,
|
||||
worktreePath,
|
||||
})
|
||||
}
|
||||
@@ -365,7 +354,13 @@ export async function handleColumnChange(panel: KanbanWebviewPanel, issueNumber:
|
||||
repo: remote.repo,
|
||||
token,
|
||||
issueNumber,
|
||||
extra: { column: 'done', worktreePath: '', prMerged: true, prMergedAt: pullRequest.merged_at ?? new Date().toISOString() },
|
||||
extra: {
|
||||
column: 'done',
|
||||
worktreePath: '',
|
||||
branch: '',
|
||||
prMerged: true,
|
||||
prMergedAt: pullRequest.merged_at ?? new Date().toISOString(),
|
||||
},
|
||||
})
|
||||
logger.add({
|
||||
level: 'info',
|
||||
@@ -471,7 +466,10 @@ export async function handleColumnChange(panel: KanbanWebviewPanel, issueNumber:
|
||||
await panel.dispatchWorktreeHook('pre-remove', {
|
||||
workspaceRoot,
|
||||
worktreePath: abs,
|
||||
branch: featureBranch ?? '',
|
||||
branch: resolveFeatureBranch({
|
||||
stateBranch: featureBranchFromState,
|
||||
prHeadRef: pullRequest.headRef,
|
||||
}),
|
||||
issueNumber,
|
||||
mainBranch: settingsForHook.devBranch || 'main',
|
||||
customScriptPath: settingsForHook.worktreePreRemoveScript,
|
||||
@@ -528,6 +526,10 @@ export async function handleColumnChange(panel: KanbanWebviewPanel, issueNumber:
|
||||
}
|
||||
}
|
||||
|
||||
const featureBranch = resolveFeatureBranch({
|
||||
stateBranch: featureBranchFromState,
|
||||
prHeadRef: pullRequest.headRef,
|
||||
})
|
||||
if (featureBranch) {
|
||||
const settingsForBranchCleanup = getSettings(panel.context)
|
||||
await cleanupFeatureBranch({
|
||||
@@ -540,8 +542,16 @@ export async function handleColumnChange(panel: KanbanWebviewPanel, issueNumber:
|
||||
token,
|
||||
})
|
||||
}
|
||||
else {
|
||||
logger.add({
|
||||
level: 'warn',
|
||||
source: 'panel',
|
||||
message: `工单 #${issueNumber} 完成时未解析到 feature 分支,跳过分支清理`,
|
||||
details: `state.branch=${featureBranchFromState ?? ''} pr.head.ref=${pullRequest.headRef || ''}`,
|
||||
})
|
||||
}
|
||||
|
||||
// 6. 全部成功 → 增量推 done + 清掉 worktreePath + 标记 prMerged。
|
||||
// 6. 全部成功 → 增量推 done + 清掉 worktreePath/branch + 标记 prMerged。
|
||||
// webview 端 `{ ...issue, ...patch }` spread 会把 worktreePath 覆盖成
|
||||
// undefined,详情面板的 worktree 链接行因此消失。
|
||||
panel.postMessage({
|
||||
@@ -550,6 +560,7 @@ export async function handleColumnChange(panel: KanbanWebviewPanel, issueNumber:
|
||||
patch: {
|
||||
column: 'done',
|
||||
worktreePath: undefined,
|
||||
branch: undefined,
|
||||
prMerged: true,
|
||||
prMergedAt: pullRequest.merged_at ?? new Date().toISOString(),
|
||||
},
|
||||
@@ -558,7 +569,9 @@ export async function handleColumnChange(panel: KanbanWebviewPanel, issueNumber:
|
||||
type: 'toast/show',
|
||||
id: makeNonce(),
|
||||
level: 'success',
|
||||
message: `工单 #${issueNumber} 已完成,worktree 已清理`,
|
||||
message: featureBranch
|
||||
? `工单 #${issueNumber} 已完成,worktree 与分支 ${featureBranch} 已清理`
|
||||
: `工单 #${issueNumber} 已完成,worktree 已清理`,
|
||||
dismissOnTimer: 5000,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user