Skip to content

Commit 44ba20e

Browse files
Robert0622roberttwangclaude
authored
fix(issues): GitHub 同步的需求显示 #编号,不再和平台需求共用 <项目>-<编号> (#1517)
GitHub 同步把 GitHub issue 号写进 issue.number,而需求列表、运行列表、运行 详情、待我确认、编辑弹窗和 Bot 都把它显示成 <项目 key>-<number>,于是同一项目里 平台需求 SWP-1 与 GitHub issue #1 都显示成 SWP-1;按 SWP-1 搜索会同时命中两条, Bot 里「澄清 SWP-1」「澄清 #1」都回复「对应多个需求」,两条需求都无法用编号引用。 - web:新增 issueKeyFor(issue, project),工蜂 / GitHub 显示 #iid、TAPD 显示 TAPD ID、 平台需求显示 <项目 key>-<number>;issueKeyLabel、需求搜索、编辑弹窗标题、运行列表、 运行详情面包屑、待我确认卡片统一使用它(工蜂需求在运行和确认页也不再显示成项目编号)。 - Bot:botIssueLabel 把 GitHub 与工蜂一样显示为 #iid;解析需求引用时先按显示的编号 精确匹配,命中唯一一条就用它,只有没有精确命中时才回退到旧的编号 / 标题匹配。 Co-authored-by: roberttwang <u_dc6754cd1ee5@users.noreply.local> Co-authored-by: Claude Code <noreply@anthropic.com>
1 parent 3e05654 commit 44ba20e

7 files changed

Lines changed: 119 additions & 12 deletions

File tree

‎internal/httpapi/bot_clarify.go‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,11 @@ func (h *assistantHandlers) botClarifyMessage(ctx context.Context, bot domain.No
121121
}
122122

123123
// botIssueLabel is the requirement key shown in chats (like the platform
124-
// list: TAPD ID, 工蜂 #iid, or <project key>-<number>).
124+
// list: TAPD ID, 工蜂 / GitHub #iid, or <project key>-<number>). Tracker
125+
// issues keep the tracker number in issue.Number, so they must not use the
126+
// <project key>-<number> form that platform requirements own.
125127
func (h *assistantHandlers) botIssueLabel(issue domain.Issue) string {
126-
if issue.Source == "gongfeng" && issue.ExternalRef != nil && issue.ExternalRef.ExternalIID > 0 {
128+
if (issue.Source == "gongfeng" || issue.Source == "github") && issue.ExternalRef != nil && issue.ExternalRef.ExternalIID > 0 {
127129
return "#" + strconv.Itoa(issue.ExternalRef.ExternalIID)
128130
}
129131
if issue.Source == "tapd" && issue.ExternalRef != nil && issue.ExternalRef.ExternalID != "" {
@@ -185,14 +187,18 @@ func (h *assistantHandlers) findBotClarifyIssue(bot domain.NotificationBot, conv
185187
return issue, ""
186188
}
187189
project, _ := h.repo.Project(bot.ProjectID)
188-
var matches []domain.Issue
190+
// The displayed key is authoritative: a platform requirement LOOP-1 and a
191+
// synced GitHub issue #1 share issue.Number, and either key names exactly
192+
// one of them. Looser number or title matches apply only when no key does.
193+
var exact, matches []domain.Issue
189194
for _, issue := range h.repo.Issues() {
190195
if issue.ProjectID != bot.ProjectID {
191196
continue
192197
}
193198
label := h.botIssueLabel(issue)
194199
switch {
195200
case strings.EqualFold(label, ref):
201+
exact = append(exact, issue)
196202
case botIssueKeyPattern.MatchString(ref) && strings.EqualFold(ref, strings.TrimSpace(project.Key)+"-"+strconv.Itoa(issue.Number)):
197203
case botIssueNumPattern.MatchString(ref) && botIssueNumPattern.FindStringSubmatch(ref)[1] == strconv.Itoa(issue.Number):
198204
case strings.TrimSpace(issue.Title) == ref:
@@ -201,6 +207,9 @@ func (h *assistantHandlers) findBotClarifyIssue(bot domain.NotificationBot, conv
201207
}
202208
matches = append(matches, issue)
203209
}
210+
if len(exact) == 1 {
211+
return exact[0], ""
212+
}
204213
if len(matches) == 1 {
205214
return matches[0], ""
206215
}

‎internal/httpapi/bot_clarify_test.go‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,3 +697,39 @@ func TestChatClarificationRunsAsTheStarter(t *testing.T) {
697697
t.Fatalf("analysis ran after the starter was removed: %d rounds", len(f.inputs))
698698
}
699699
}
700+
701+
// A GitHub issue synced into the project keeps the tracker number in
702+
// issue.Number, so it shares the number of the platform requirement LOOP-7.
703+
// Each displayed key names exactly one requirement; the bare number stays
704+
// ambiguous and asks for a key.
705+
func TestChatClarificationKeysOfSyncedGitHubIssues(t *testing.T) {
706+
f := newClarifyChatFixture(t, domain.BotChannelFeishu)
707+
if err := f.s.PutIssue(domain.Issue{ID: "gh-repo-7", ProjectID: "p", Number: 7, Kind: "issue", Source: "github", Title: "导出报表超时",
708+
ExternalRef: &domain.ExternalRef{Source: "github", ExternalID: "990007", ExternalIID: 7, ExternalType: "issue"}}); err != nil {
709+
t.Fatal(err)
710+
}
711+
local, _ := f.s.Issue("iss-7")
712+
gh, _ := f.s.Issue("gh-repo-7")
713+
if got := f.h.botIssueLabel(gh); got != "#7" {
714+
t.Fatalf("GitHub issue label = %q, want #7", got)
715+
}
716+
if got := f.h.botIssueLabel(local); got != "LOOP-7" {
717+
t.Fatalf("platform requirement label = %q, want LOOP-7", got)
718+
}
719+
for ref, want := range map[string]string{"LOOP-7": "iss-7", "loop-7": "iss-7", "#7": "gh-repo-7", "导出报表超时": "gh-repo-7"} {
720+
issue, refusal := f.h.findBotClarifyIssue(f.bot, domain.BotConversation{}, ref)
721+
if refusal != "" || issue.ID != want {
722+
t.Fatalf("ref %q = %q (%s), want %s", ref, issue.ID, refusal, want)
723+
}
724+
}
725+
if _, refusal := f.h.findBotClarifyIssue(f.bot, domain.BotConversation{}, "7"); !strings.Contains(refusal, "对应多个需求") {
726+
t.Fatalf("bare number refusal = %q", refusal)
727+
}
728+
// Without a platform requirement of that number the old key still resolves.
729+
if err := f.s.DeleteIssue("iss-7"); err != nil {
730+
t.Fatal(err)
731+
}
732+
if issue, refusal := f.h.findBotClarifyIssue(f.bot, domain.BotConversation{}, "LOOP-7"); refusal != "" || issue.ID != "gh-repo-7" {
733+
t.Fatalf("legacy key = %q (%s)", issue.ID, refusal)
734+
}
735+
}

‎web/app/approvals.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ function approvalCardHTML(r){
560560
const alignRun=r.workflowId==='scheduled-baseline-align'||r.workflowSnapshot?.id==='scheduled-baseline-align';
561561
const repoName=r.repository?.name;
562562
const title=alignRun?(repoName?`${repoName} · 确认对齐基线`:'定时任务 · 确认对齐基线'):issue?.title||r.workflowSnapshot?.name||r.workflowId;
563-
const key=alignRun?'定时任务基线':issue?`${(state.data.projects||[]).find(p=>p.id===issue.projectId)?.key||'ISS'}-${issue.number}`:'未关联需求';
563+
const key=alignRun?'定时任务基线':issue?issueKeyFor(issue,(state.data.projects||[]).find(p=>p.id===issue.projectId)):'未关联需求';
564564
const keyHTML=issue&&!alignRun?`<code class="ap-key">${escapeHTML(key)}</code>`:`<span class="ap-key">${escapeHTML(key)}</span>`;
565565
const sep='<span class="ap-sep" aria-hidden="true">·</span>';
566566
const sideButton=issue?`<button class="button ghost small" data-open-issue="${escapeHTML(issue.id)}">打开需求</button>`:`<button class="button ghost small" data-open-logs="${escapeHTML(r.id)}">${alignRun?'查看对齐详情':'排查日志'}</button>`;

‎web/app/issues.js‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,26 @@ function normalizeIssueTitleSearch(value){
101101
return String(value||'').normalize('NFKC').toLocaleLowerCase().replace(/[\s\p{P}\p{S}]+/gu,'');
102102
}
103103

104+
// issueKeyFor is the requirement key shown everywhere (list, drawer, runs,
105+
// approvals, search): 工蜂 and GitHub issues keep their tracker #iid, TAPD
106+
// stories their TAPD ID, platform requirements <project key>-<number>.
107+
// Tracker-synced issues store the tracker number in issue.number, so the
108+
// project-key form would collide with platform requirements of the same number.
109+
function issueKeyFor(issue,project){
110+
const ref=issue?.externalRef;
111+
if((issue?.source==='gongfeng'||issue?.source==='github')&&ref?.externalIid)return `#${ref.externalIid}`;
112+
if(issue?.source==='tapd'&&ref?.externalId)return String(ref.externalId);
113+
return `${project?.key||'ISS'}-${issue?.number||''}`;
114+
}
115+
104116
function issueMatchesQuery(issue,project,query){
105117
const raw=String(query||'').trim().toLocaleLowerCase();
106118
if(!raw)return true;
107119
const title=String(issue?.title||''),normalizedTitle=normalizeIssueTitleSearch(title),normalizedQuery=normalizeIssueTitleSearch(raw);
108120
const titleTokens=raw.split(/[\s\p{P}\p{S}]+/u).map(normalizeIssueTitleSearch).filter(Boolean);
109121
if(normalizedQuery&&normalizedTitle.includes(normalizedQuery))return true;
110122
if(titleTokens.length&&titleTokens.every(token=>normalizedTitle.includes(token)))return true;
111-
const key=`${project?.key||'ISS'}-${issue?.number||''}`,external=issue?.externalRef?.externalId||issue?.externalRef?.externalIid||'';
123+
const key=issueKeyFor(issue,project),external=issue?.externalRef?.externalId||issue?.externalRef?.externalIid||'';
112124
return `${key} ${title} ${issue?.description||''} ${external}`.toLocaleLowerCase().includes(raw);
113125
}
114126

@@ -330,10 +342,7 @@ function issueMatchesStatusFilter(issue,filter){
330342
function issuePriorityLabel(value){return ({urgent:'紧急',high:'高',medium:'中',low:'低'}[value]||value||'—')}
331343
function taskStatusLabel(value){return ({queued:'排队中',dispatched:'已调度',running:'运行中',completed:'已完成',failed:'失败',cancelled:'已取消'}[value]||value||'—')}
332344
function issueKeyLabel(i){
333-
if(i.source==='gongfeng'&&i.externalRef?.externalIid) return `#${i.externalRef.externalIid}`;
334-
if(i.source==='tapd'&&i.externalRef?.externalId) return String(i.externalRef.externalId);
335-
const p=(state.data.projects||[]).find(x=>x.id===i.projectId);
336-
return `${p?.key||'ISS'}-${i.number||''}`;
345+
return issueKeyFor(i,(state.data.projects||[]).find(x=>x.id===i?.projectId));
337346
}
338347
function issueKeyMarkup(i){
339348
const raw=String(issueKeyLabel(i)||'');
@@ -497,7 +506,7 @@ function openIssue(issue=null){
497506
renderIssueRepositoryBranchInputs(f.elements.baseBranch,$('#issueBaseBranchHint'),$('#issueRepositoryBranches'),selectedIssueRepositoryIds(),v.repositoryBranches||{[v.repositoryId]:storedIssueWorkBranch(v)});
498507
f.elements.projectId.onchange=()=>{fillIssueRepositories(f.elements.projectId.value);fillIssueAssignees(f.elements.projectId.value,'');renderIssueRepositoryBranchInputs(f.elements.baseBranch,$('#issueBaseBranchHint'),$('#issueRepositoryBranches'),selectedIssueRepositoryIds(),{})};
499508
$('#issueRepoChecks').onchange=refreshIssueBaseBranchInput;
500-
$('#issueModalTitle').textContent=issue?`${(projects.find(p=>p.id===v.projectId)?.key||'ISS')}-${v.number} ${v.title}`:'新建工作项';
509+
$('#issueModalTitle').textContent=issue?`${issueKeyFor(v,projects.find(p=>p.id===v.projectId))} ${v.title}`:'新建工作项';
501510
const task=(state.data.tasks||[]).find(t=>t.id===v.latestTaskId);
502511
let stateHtml=task?`最近任务 ${escapeHTML(task.id)} · ${taskStatusLabel(task.status)} · Run ${escapeHTML(task.runId)}`:'';
503512
if(v.automationState==='ignored')stateHtml+=`${stateHtml?'<br>':''}定时 LOOP:<b>已忽略</b>`;

‎web/app/runs.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ function runRowHTML(r,workflows){
297297
const isPaused=Boolean(r.pauseRequested||r.status==='paused');
298298
const isDeletable=r.status!=='queued'&&(!['running','waiting'].includes(r.status)||isPaused);
299299
const sep='<span class="run-sep">·</span>';
300-
const meta=group?`<span>${relativeTime(r.createdAt)}</span>${runTriggerChip(ctx.task)}`:`${ctx.issue?`<span class="run-ref">${escapeHTML(ctx.project?.key||'ISS')}-${escapeHTML(ctx.issue.number)}</span>${sep}`:''}<span class="run-meta-sop">${escapeHTML(sop)}</span>${sep}<span>${relativeTime(r.createdAt)}</span>${runTriggerChip(ctx.task)}`;
300+
const meta=group?`<span>${relativeTime(r.createdAt)}</span>${runTriggerChip(ctx.task)}`:`${ctx.issue?`<span class="run-ref">${escapeHTML(issueKeyFor(ctx.issue,ctx.project))}</span>${sep}`:''}<span class="run-meta-sop">${escapeHTML(sop)}</span>${sep}<span>${relativeTime(r.createdAt)}</span>${runTriggerChip(ctx.task)}`;
301301
const progress=group?'<div class="run-row-progress is-empty">—</div>':`<div class="run-row-progress"><span class="run-progress-text">${p.done}/${p.total}</span><div class="run-progress tone-${runStatusTone(r)}"><i style="width:${p.pct}%"></i></div></div>`;
302302
const time=group?'<span class="run-row-time"></span>':`<span class="run-row-time" title="${escapeHTML(runTimingTitle(r))}">${runElapsed(r)}</span>`;
303303
const actions=`<button type="button" class="run-row-action run-view-btn" data-view-run="${escapeHTML(r.id)}" aria-label="查看详情" title="查看详情">${runIconSlot('eye',15)}</button>${isDeletable?`<button type="button" class="run-row-action run-del-btn" data-delete-run="${escapeHTML(r.id)}" aria-label="删除记录" title="删除记录">${runIconSlot('trash',15)}</button>`:''}`;
@@ -1805,7 +1805,7 @@ function renderRunDetail(r){
18051805
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||[]);
18061806
/** 首次渲染与实时更新使用同一节点活动判断。 */
18071807
const inspectorRunning=nodeInspectorIsRunning(r,selected?.id);
1808-
const issueRef=ctx.issue?`${escapeHTML(ctx.project?.key||'TASK')}-${ctx.issue.number}`:'独立运行';
1808+
const issueRef=ctx.issue?escapeHTML(issueKeyFor(ctx.issue,ctx.project)):'独立运行';
18091809
const alignPanelHTML=r.workflowId==='scheduled-baseline-align'?alignConflictPanelHTML(r):'';
18101810
const logBusy=state.runLogs?.runId===pg.runId&&state.runLogs.nodeId===pg.nodeId&&state.runLogs.loading&&!logPage;
18111811
const previewEnabled=runPreviewDeclared(r);

‎web/syntax_test.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,6 +2466,7 @@ eval(code.slice(code.indexOf('function huiIcon('), code.indexOf('// stage.key al
24662466
eval(code.slice(code.indexOf('function waitingNodeId('), code.indexOf('function failedNodeId(')));
24672467
eval(code.slice(code.indexOf('function restoredSOPResumeNode('), code.indexOf('function approvalCalloutHTML(')));
24682468
eval(code.slice(code.indexOf('function approvalStatusBadgeHTML('), code.indexOf('function closeApprovalMoreMenus(')));
2469+
eval(code.slice(code.indexOf('function issueKeyFor('), code.indexOf('function issueMatchesQuery(')));
24692470
const between = (html, from, to) => html.slice(html.indexOf(from), html.indexOf(to, html.indexOf(from)));
24702471
const node = {id:'gate', name:'confirm-brief', type:'agent'};
24712472
const waiting = {id:'run-1', status:'waiting', workflowSnapshot:{nodes:[node]}, nodes:{gate:{status:'waiting_approval'}}};

‎webtest/tests/issue-keys.test.mjs‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import test from 'node:test';
2+
import assert from 'node:assert/strict';
3+
import { loadApp } from '../lib/load-app.mjs';
4+
5+
// GitHub and 工蜂 sync stores the tracker number in issue.number, so a synced
6+
// issue and a platform requirement of the same project can both have number 1.
7+
// Every surface must show the same, unambiguous key for each of them.
8+
test('synced tracker issues keep their tracker key on every surface', async (t) => {
9+
const app = await loadApp();
10+
t.after(app.close);
11+
const result = structuredClone(await app.evaluate(`(() => {
12+
state.data.projects[0].key = 'SWP';
13+
const local = {id:'local-1',projectId:'project-1',number:1,title:'title_case 吞掉连续空格',source:'local',status:'todo',priority:'medium'};
14+
const github = {id:'gh-repo-1',projectId:'project-1',number:1,title:'word_count 全角空格',source:'github',kind:'issue',status:'todo',priority:'medium',
15+
externalRef:{source:'github',externalId:'990001',externalIid:1,externalType:'issue'}};
16+
const gongfeng = {id:'gf-repo-5',projectId:'project-1',number:5,title:'工蜂缺陷',source:'gongfeng',status:'todo',priority:'medium',
17+
externalRef:{source:'gongfeng',externalId:'77005',externalIid:5}};
18+
const tapd = {id:'tapd-1',projectId:'project-1',number:2,title:'TAPD 需求',source:'tapd',status:'todo',priority:'medium',
19+
externalRef:{source:'tapd',externalId:'1010101'}};
20+
const plain = {id:'p-9',projectId:'missing',number:9,title:'无项目',status:'todo'};
21+
state.data.issues = [local, github, gongfeng, tapd];
22+
state.projectFilter = 'project-1';
23+
state.sourceFilter=''; state.issueStatusFilter=''; state.issueAssigneeFilter=''; state.issueRunFilter='';
24+
const search = q => { state.issueQuery = q; return filteredIssues().map(i => i.id); };
25+
state.data.tasks = [{id:'t1',issueId:'local-1',runId:'run-local'},{id:'t2',issueId:'gh-repo-1',runId:'run-gh'}];
26+
const run = (id, issueId) => ({id, workflowId:'flow-1', status:'waiting', nodes:{}, createdAt:new Date().toISOString(),
27+
executionContext:{issueId}, workflowSnapshot:{id:'flow-1', name:'LOOP', nodes:[{id:'accept',name:'人工验收',type:'approval'}]}});
28+
const runRef = r => { const d = document.createElement('div'); d.innerHTML = runRowHTML(r, state.data.workflows || []); return d.querySelector('.run-ref')?.textContent; };
29+
const apKey = r => { const d = document.createElement('div'); d.innerHTML = approvalCardHTML(r); return d.querySelector('.ap-key')?.textContent; };
30+
openIssue(github);
31+
const modalGitHub = document.querySelector('#issueModalTitle').textContent;
32+
openIssue(local);
33+
const modalLocal = document.querySelector('#issueModalTitle').textContent;
34+
return {
35+
labels: [local, github, gongfeng, tapd, plain].map(issueKeyLabel),
36+
searchLocalKey: search('SWP-1'),
37+
searchGitHubKey: search('#1'),
38+
searchGongfengKey: search('#5'),
39+
runRefs: [runRef(run('run-local','local-1')), runRef(run('run-gh','gh-repo-1'))],
40+
approvalKeys: [apKey(run('run-local','local-1')), apKey(run('run-gh','gh-repo-1'))],
41+
modalGitHub, modalLocal,
42+
};
43+
})()`));
44+
assert.deepEqual(result.labels, ['SWP-1', '#1', '#5', '1010101', 'ISS-9']);
45+
assert.deepEqual(result.searchLocalKey, ['local-1']);
46+
assert.deepEqual(result.searchGitHubKey, ['gh-repo-1']);
47+
assert.deepEqual(result.searchGongfengKey, ['gf-repo-5']);
48+
assert.deepEqual(result.runRefs, ['SWP-1', '#1']);
49+
assert.deepEqual(result.approvalKeys, ['SWP-1', '#1']);
50+
assert.equal(result.modalGitHub, '#1 word_count 全角空格');
51+
assert.equal(result.modalLocal, 'SWP-1 title_case 吞掉连续空格');
52+
});

0 commit comments

Comments
 (0)