From 45093f424a9a37684ec055b148b684355681361f Mon Sep 17 00:00:00 2001 From: roberttwang Date: Fri, 27 Nov 2026 22:55:28 +0000 Subject: [PATCH] =?UTF-8?q?fix(issues):=20GitHub=20=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E7=9A=84=E9=9C=80=E6=B1=82=E6=98=BE=E7=A4=BA=20#=E7=BC=96?= =?UTF-8?q?=E5=8F=B7=EF=BC=8C=E4=B8=8D=E5=86=8D=E5=92=8C=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E9=9C=80=E6=B1=82=E5=85=B1=E7=94=A8=20<=E9=A1=B9=E7=9B=AE>-?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GitHub 同步把 GitHub issue 号写进 issue.number,而需求列表、运行列表、运行 详情、待我确认、编辑弹窗和 Bot 都把它显示成 <项目 key>-,于是同一项目里 平台需求 SWP-1 与 GitHub issue #1 都显示成 SWP-1;按 SWP-1 搜索会同时命中两条, Bot 里「澄清 SWP-1」「澄清 #1」都回复「对应多个需求」,两条需求都无法用编号引用。 - web:新增 issueKeyFor(issue, project),工蜂 / GitHub 显示 #iid、TAPD 显示 TAPD ID、 平台需求显示 <项目 key>-;issueKeyLabel、需求搜索、编辑弹窗标题、运行列表、 运行详情面包屑、待我确认卡片统一使用它(工蜂需求在运行和确认页也不再显示成项目编号)。 - Bot:botIssueLabel 把 GitHub 与工蜂一样显示为 #iid;解析需求引用时先按显示的编号 精确匹配,命中唯一一条就用它,只有没有精确命中时才回退到旧的编号 / 标题匹配。 Co-Authored-By: Claude Code --- internal/httpapi/bot_clarify.go | 15 ++++++-- internal/httpapi/bot_clarify_test.go | 36 +++++++++++++++++++ web/app/approvals.js | 2 +- web/app/issues.js | 21 +++++++---- web/app/runs.js | 4 +-- web/syntax_test.go | 1 + webtest/tests/issue-keys.test.mjs | 52 ++++++++++++++++++++++++++++ 7 files changed, 119 insertions(+), 12 deletions(-) create mode 100644 webtest/tests/issue-keys.test.mjs diff --git a/internal/httpapi/bot_clarify.go b/internal/httpapi/bot_clarify.go index 91c86d45f..5995f90e8 100644 --- a/internal/httpapi/bot_clarify.go +++ b/internal/httpapi/bot_clarify.go @@ -121,9 +121,11 @@ func (h *assistantHandlers) botClarifyMessage(ctx context.Context, bot domain.No } // botIssueLabel is the requirement key shown in chats (like the platform -// list: TAPD ID, 工蜂 #iid, or -). +// list: TAPD ID, 工蜂 / GitHub #iid, or -). Tracker +// issues keep the tracker number in issue.Number, so they must not use the +// - form that platform requirements own. func (h *assistantHandlers) botIssueLabel(issue domain.Issue) string { - if issue.Source == "gongfeng" && issue.ExternalRef != nil && issue.ExternalRef.ExternalIID > 0 { + if (issue.Source == "gongfeng" || issue.Source == "github") && issue.ExternalRef != nil && issue.ExternalRef.ExternalIID > 0 { return "#" + strconv.Itoa(issue.ExternalRef.ExternalIID) } if issue.Source == "tapd" && issue.ExternalRef != nil && issue.ExternalRef.ExternalID != "" { @@ -185,7 +187,10 @@ func (h *assistantHandlers) findBotClarifyIssue(bot domain.NotificationBot, conv return issue, "" } project, _ := h.repo.Project(bot.ProjectID) - var matches []domain.Issue + // The displayed key is authoritative: a platform requirement LOOP-1 and a + // synced GitHub issue #1 share issue.Number, and either key names exactly + // one of them. Looser number or title matches apply only when no key does. + var exact, matches []domain.Issue for _, issue := range h.repo.Issues() { if issue.ProjectID != bot.ProjectID { continue @@ -193,6 +198,7 @@ func (h *assistantHandlers) findBotClarifyIssue(bot domain.NotificationBot, conv label := h.botIssueLabel(issue) switch { case strings.EqualFold(label, ref): + exact = append(exact, issue) case botIssueKeyPattern.MatchString(ref) && strings.EqualFold(ref, strings.TrimSpace(project.Key)+"-"+strconv.Itoa(issue.Number)): case botIssueNumPattern.MatchString(ref) && botIssueNumPattern.FindStringSubmatch(ref)[1] == strconv.Itoa(issue.Number): case strings.TrimSpace(issue.Title) == ref: @@ -201,6 +207,9 @@ func (h *assistantHandlers) findBotClarifyIssue(bot domain.NotificationBot, conv } matches = append(matches, issue) } + if len(exact) == 1 { + return exact[0], "" + } if len(matches) == 1 { return matches[0], "" } diff --git a/internal/httpapi/bot_clarify_test.go b/internal/httpapi/bot_clarify_test.go index db98062ca..e1e8d1b7d 100644 --- a/internal/httpapi/bot_clarify_test.go +++ b/internal/httpapi/bot_clarify_test.go @@ -697,3 +697,39 @@ func TestChatClarificationRunsAsTheStarter(t *testing.T) { t.Fatalf("analysis ran after the starter was removed: %d rounds", len(f.inputs)) } } + +// A GitHub issue synced into the project keeps the tracker number in +// issue.Number, so it shares the number of the platform requirement LOOP-7. +// Each displayed key names exactly one requirement; the bare number stays +// ambiguous and asks for a key. +func TestChatClarificationKeysOfSyncedGitHubIssues(t *testing.T) { + f := newClarifyChatFixture(t, domain.BotChannelFeishu) + if err := f.s.PutIssue(domain.Issue{ID: "gh-repo-7", ProjectID: "p", Number: 7, Kind: "issue", Source: "github", Title: "导出报表超时", + ExternalRef: &domain.ExternalRef{Source: "github", ExternalID: "990007", ExternalIID: 7, ExternalType: "issue"}}); err != nil { + t.Fatal(err) + } + local, _ := f.s.Issue("iss-7") + gh, _ := f.s.Issue("gh-repo-7") + if got := f.h.botIssueLabel(gh); got != "#7" { + t.Fatalf("GitHub issue label = %q, want #7", got) + } + if got := f.h.botIssueLabel(local); got != "LOOP-7" { + t.Fatalf("platform requirement label = %q, want LOOP-7", got) + } + for ref, want := range map[string]string{"LOOP-7": "iss-7", "loop-7": "iss-7", "#7": "gh-repo-7", "导出报表超时": "gh-repo-7"} { + issue, refusal := f.h.findBotClarifyIssue(f.bot, domain.BotConversation{}, ref) + if refusal != "" || issue.ID != want { + t.Fatalf("ref %q = %q (%s), want %s", ref, issue.ID, refusal, want) + } + } + if _, refusal := f.h.findBotClarifyIssue(f.bot, domain.BotConversation{}, "7"); !strings.Contains(refusal, "对应多个需求") { + t.Fatalf("bare number refusal = %q", refusal) + } + // Without a platform requirement of that number the old key still resolves. + if err := f.s.DeleteIssue("iss-7"); err != nil { + t.Fatal(err) + } + if issue, refusal := f.h.findBotClarifyIssue(f.bot, domain.BotConversation{}, "LOOP-7"); refusal != "" || issue.ID != "gh-repo-7" { + t.Fatalf("legacy key = %q (%s)", issue.ID, refusal) + } +} diff --git a/web/app/approvals.js b/web/app/approvals.js index 19dc6cfcd..338d607f1 100644 --- a/web/app/approvals.js +++ b/web/app/approvals.js @@ -560,7 +560,7 @@ function approvalCardHTML(r){ const alignRun=r.workflowId==='scheduled-baseline-align'||r.workflowSnapshot?.id==='scheduled-baseline-align'; const repoName=r.repository?.name; const title=alignRun?(repoName?`${repoName} · 确认对齐基线`:'定时任务 · 确认对齐基线'):issue?.title||r.workflowSnapshot?.name||r.workflowId; - const key=alignRun?'定时任务基线':issue?`${(state.data.projects||[]).find(p=>p.id===issue.projectId)?.key||'ISS'}-${issue.number}`:'未关联需求'; + const key=alignRun?'定时任务基线':issue?issueKeyFor(issue,(state.data.projects||[]).find(p=>p.id===issue.projectId)):'未关联需求'; const keyHTML=issue&&!alignRun?`${escapeHTML(key)}`:`${escapeHTML(key)}`; const sep=''; const sideButton=issue?``:``; diff --git a/web/app/issues.js b/web/app/issues.js index 00c7bef2e..e96cd8bf0 100644 --- a/web/app/issues.js +++ b/web/app/issues.js @@ -101,6 +101,18 @@ function normalizeIssueTitleSearch(value){ return String(value||'').normalize('NFKC').toLocaleLowerCase().replace(/[\s\p{P}\p{S}]+/gu,''); } +// issueKeyFor is the requirement key shown everywhere (list, drawer, runs, +// approvals, search): 工蜂 and GitHub issues keep their tracker #iid, TAPD +// stories their TAPD ID, platform requirements -. +// Tracker-synced issues store the tracker number in issue.number, so the +// project-key form would collide with platform requirements of the same number. +function issueKeyFor(issue,project){ + const ref=issue?.externalRef; + if((issue?.source==='gongfeng'||issue?.source==='github')&&ref?.externalIid)return `#${ref.externalIid}`; + if(issue?.source==='tapd'&&ref?.externalId)return String(ref.externalId); + return `${project?.key||'ISS'}-${issue?.number||''}`; +} + function issueMatchesQuery(issue,project,query){ const raw=String(query||'').trim().toLocaleLowerCase(); if(!raw)return true; @@ -108,7 +120,7 @@ function issueMatchesQuery(issue,project,query){ const titleTokens=raw.split(/[\s\p{P}\p{S}]+/u).map(normalizeIssueTitleSearch).filter(Boolean); if(normalizedQuery&&normalizedTitle.includes(normalizedQuery))return true; if(titleTokens.length&&titleTokens.every(token=>normalizedTitle.includes(token)))return true; - const key=`${project?.key||'ISS'}-${issue?.number||''}`,external=issue?.externalRef?.externalId||issue?.externalRef?.externalIid||''; + const key=issueKeyFor(issue,project),external=issue?.externalRef?.externalId||issue?.externalRef?.externalIid||''; return `${key} ${title} ${issue?.description||''} ${external}`.toLocaleLowerCase().includes(raw); } @@ -330,10 +342,7 @@ function issueMatchesStatusFilter(issue,filter){ function issuePriorityLabel(value){return ({urgent:'紧急',high:'高',medium:'中',low:'低'}[value]||value||'—')} function taskStatusLabel(value){return ({queued:'排队中',dispatched:'已调度',running:'运行中',completed:'已完成',failed:'失败',cancelled:'已取消'}[value]||value||'—')} function issueKeyLabel(i){ - if(i.source==='gongfeng'&&i.externalRef?.externalIid) return `#${i.externalRef.externalIid}`; - if(i.source==='tapd'&&i.externalRef?.externalId) return String(i.externalRef.externalId); - const p=(state.data.projects||[]).find(x=>x.id===i.projectId); - return `${p?.key||'ISS'}-${i.number||''}`; + return issueKeyFor(i,(state.data.projects||[]).find(x=>x.id===i?.projectId)); } function issueKeyMarkup(i){ const raw=String(issueKeyLabel(i)||''); @@ -497,7 +506,7 @@ function openIssue(issue=null){ renderIssueRepositoryBranchInputs(f.elements.baseBranch,$('#issueBaseBranchHint'),$('#issueRepositoryBranches'),selectedIssueRepositoryIds(),v.repositoryBranches||{[v.repositoryId]:storedIssueWorkBranch(v)}); f.elements.projectId.onchange=()=>{fillIssueRepositories(f.elements.projectId.value);fillIssueAssignees(f.elements.projectId.value,'');renderIssueRepositoryBranchInputs(f.elements.baseBranch,$('#issueBaseBranchHint'),$('#issueRepositoryBranches'),selectedIssueRepositoryIds(),{})}; $('#issueRepoChecks').onchange=refreshIssueBaseBranchInput; - $('#issueModalTitle').textContent=issue?`${(projects.find(p=>p.id===v.projectId)?.key||'ISS')}-${v.number} ${v.title}`:'新建工作项'; + $('#issueModalTitle').textContent=issue?`${issueKeyFor(v,projects.find(p=>p.id===v.projectId))} ${v.title}`:'新建工作项'; const task=(state.data.tasks||[]).find(t=>t.id===v.latestTaskId); let stateHtml=task?`最近任务 ${escapeHTML(task.id)} · ${taskStatusLabel(task.status)} · Run ${escapeHTML(task.runId)}`:''; if(v.automationState==='ignored')stateHtml+=`${stateHtml?'
':''}定时 LOOP:已忽略`; diff --git a/web/app/runs.js b/web/app/runs.js index 807f64dcb..ca1f9a530 100644 --- a/web/app/runs.js +++ b/web/app/runs.js @@ -297,7 +297,7 @@ function runRowHTML(r,workflows){ const isPaused=Boolean(r.pauseRequested||r.status==='paused'); const isDeletable=r.status!=='queued'&&(!['running','waiting'].includes(r.status)||isPaused); const sep='·'; - const meta=group?`${relativeTime(r.createdAt)}${runTriggerChip(ctx.task)}`:`${ctx.issue?`${escapeHTML(ctx.project?.key||'ISS')}-${escapeHTML(ctx.issue.number)}${sep}`:''}${escapeHTML(sop)}${sep}${relativeTime(r.createdAt)}${runTriggerChip(ctx.task)}`; + const meta=group?`${relativeTime(r.createdAt)}${runTriggerChip(ctx.task)}`:`${ctx.issue?`${escapeHTML(issueKeyFor(ctx.issue,ctx.project))}${sep}`:''}${escapeHTML(sop)}${sep}${relativeTime(r.createdAt)}${runTriggerChip(ctx.task)}`; const progress=group?'
—
':`
${p.done}/${p.total}
`; const time=group?'':`${runElapsed(r)}`; const actions=`${isDeletable?``:''}`; @@ -1805,7 +1805,7 @@ function renderRunDetail(r){ const pickNodes=runIsGroupMode(r)?(graphNodes.length?graphNodes:nodes):nodes;if(!state.selectedRunNode||!pickNodes.some(n=>n.id===state.selectedRunNode)){state.selectedRunNode=pickNodes.find(n=>['running','waiting_approval','failed','cancelled'].includes(r.nodes?.[n.id]?.status))?.id||pickNodes.find(n=>r.nodes?.[n.id]?.status==='succeeded')?.id||pickNodes[0]?.id}const pg=runPageTarget(r,state.selectedRunNode);const selected=pickNodes.find(n=>n.id===state.selectedRunNode)||nodes.find(n=>n.id===state.selectedRunNode),nr=r.nodes?.[selected?.id]||{},nodeArtifacts=(r.artifacts||[]).filter(a=>a.nodeId===selected?.id),logPage=state.runLogs?.runId===pg.runId&&state.runLogs.nodeId===pg.nodeId&&state.runLogs.loaded?state.runLogs:null,telAdapter=state.runTelemetryAdapter||'live',telPage=state.runTelemetry?.runId===pg.runId&&state.runTelemetry.nodeId===pg.nodeId&&state.runTelemetry.adapter===telAdapter&&state.runTelemetry.loaded?state.runTelemetry:null,telemetry=compactTelemetry(telPage?.items||[]); /** 首次渲染与实时更新使用同一节点活动判断。 */ const inspectorRunning=nodeInspectorIsRunning(r,selected?.id); - const issueRef=ctx.issue?`${escapeHTML(ctx.project?.key||'TASK')}-${ctx.issue.number}`:'独立运行'; + const issueRef=ctx.issue?escapeHTML(issueKeyFor(ctx.issue,ctx.project)):'独立运行'; const alignPanelHTML=r.workflowId==='scheduled-baseline-align'?alignConflictPanelHTML(r):''; const logBusy=state.runLogs?.runId===pg.runId&&state.runLogs.nodeId===pg.nodeId&&state.runLogs.loading&&!logPage; const previewEnabled=runPreviewDeclared(r); diff --git a/web/syntax_test.go b/web/syntax_test.go index a16e2a2f6..462e18568 100644 --- a/web/syntax_test.go +++ b/web/syntax_test.go @@ -2466,6 +2466,7 @@ eval(code.slice(code.indexOf('function huiIcon('), code.indexOf('// stage.key al eval(code.slice(code.indexOf('function waitingNodeId('), code.indexOf('function failedNodeId('))); eval(code.slice(code.indexOf('function restoredSOPResumeNode('), code.indexOf('function approvalCalloutHTML('))); eval(code.slice(code.indexOf('function approvalStatusBadgeHTML('), code.indexOf('function closeApprovalMoreMenus('))); +eval(code.slice(code.indexOf('function issueKeyFor('), code.indexOf('function issueMatchesQuery('))); const between = (html, from, to) => html.slice(html.indexOf(from), html.indexOf(to, html.indexOf(from))); const node = {id:'gate', name:'confirm-brief', type:'agent'}; const waiting = {id:'run-1', status:'waiting', workflowSnapshot:{nodes:[node]}, nodes:{gate:{status:'waiting_approval'}}}; diff --git a/webtest/tests/issue-keys.test.mjs b/webtest/tests/issue-keys.test.mjs new file mode 100644 index 000000000..30b0d75ed --- /dev/null +++ b/webtest/tests/issue-keys.test.mjs @@ -0,0 +1,52 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { loadApp } from '../lib/load-app.mjs'; + +// GitHub and 工蜂 sync stores the tracker number in issue.number, so a synced +// issue and a platform requirement of the same project can both have number 1. +// Every surface must show the same, unambiguous key for each of them. +test('synced tracker issues keep their tracker key on every surface', async (t) => { + const app = await loadApp(); + t.after(app.close); + const result = structuredClone(await app.evaluate(`(() => { + state.data.projects[0].key = 'SWP'; + const local = {id:'local-1',projectId:'project-1',number:1,title:'title_case 吞掉连续空格',source:'local',status:'todo',priority:'medium'}; + const github = {id:'gh-repo-1',projectId:'project-1',number:1,title:'word_count 全角空格',source:'github',kind:'issue',status:'todo',priority:'medium', + externalRef:{source:'github',externalId:'990001',externalIid:1,externalType:'issue'}}; + const gongfeng = {id:'gf-repo-5',projectId:'project-1',number:5,title:'工蜂缺陷',source:'gongfeng',status:'todo',priority:'medium', + externalRef:{source:'gongfeng',externalId:'77005',externalIid:5}}; + const tapd = {id:'tapd-1',projectId:'project-1',number:2,title:'TAPD 需求',source:'tapd',status:'todo',priority:'medium', + externalRef:{source:'tapd',externalId:'1010101'}}; + const plain = {id:'p-9',projectId:'missing',number:9,title:'无项目',status:'todo'}; + state.data.issues = [local, github, gongfeng, tapd]; + state.projectFilter = 'project-1'; + state.sourceFilter=''; state.issueStatusFilter=''; state.issueAssigneeFilter=''; state.issueRunFilter=''; + const search = q => { state.issueQuery = q; return filteredIssues().map(i => i.id); }; + state.data.tasks = [{id:'t1',issueId:'local-1',runId:'run-local'},{id:'t2',issueId:'gh-repo-1',runId:'run-gh'}]; + const run = (id, issueId) => ({id, workflowId:'flow-1', status:'waiting', nodes:{}, createdAt:new Date().toISOString(), + executionContext:{issueId}, workflowSnapshot:{id:'flow-1', name:'LOOP', nodes:[{id:'accept',name:'人工验收',type:'approval'}]}}); + const runRef = r => { const d = document.createElement('div'); d.innerHTML = runRowHTML(r, state.data.workflows || []); return d.querySelector('.run-ref')?.textContent; }; + const apKey = r => { const d = document.createElement('div'); d.innerHTML = approvalCardHTML(r); return d.querySelector('.ap-key')?.textContent; }; + openIssue(github); + const modalGitHub = document.querySelector('#issueModalTitle').textContent; + openIssue(local); + const modalLocal = document.querySelector('#issueModalTitle').textContent; + return { + labels: [local, github, gongfeng, tapd, plain].map(issueKeyLabel), + searchLocalKey: search('SWP-1'), + searchGitHubKey: search('#1'), + searchGongfengKey: search('#5'), + runRefs: [runRef(run('run-local','local-1')), runRef(run('run-gh','gh-repo-1'))], + approvalKeys: [apKey(run('run-local','local-1')), apKey(run('run-gh','gh-repo-1'))], + modalGitHub, modalLocal, + }; + })()`)); + assert.deepEqual(result.labels, ['SWP-1', '#1', '#5', '1010101', 'ISS-9']); + assert.deepEqual(result.searchLocalKey, ['local-1']); + assert.deepEqual(result.searchGitHubKey, ['gh-repo-1']); + assert.deepEqual(result.searchGongfengKey, ['gf-repo-5']); + assert.deepEqual(result.runRefs, ['SWP-1', '#1']); + assert.deepEqual(result.approvalKeys, ['SWP-1', '#1']); + assert.equal(result.modalGitHub, '#1 word_count 全角空格'); + assert.equal(result.modalLocal, 'SWP-1 title_case 吞掉连续空格'); +});