【架构优化】合并 tracker 中 ImportTAPDStory/ResyncTAPDIssue 重复的单条 TAPD 记录读取与按类型 upsert 分派

未關閉
#422 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@fx-kurumi 已經在處理了。

開始於 2026年11月13日。

  • #423 來自 @fx-kurumi —— 未關閉

評估

難度
3/5
預估耗時
1-2 天
新手友好度
25/100
Issue 類型
重構
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
go
領域
backend

研究方向

The duplicated fetch logic sits in ImportTAPDStory and ResyncTAPDIssue in internal/tracker/service.go, which both call proxy_execute_tool and then dispatch to upsertTAPDTask, upsertTAPDBug or upsertTAPDStory. Read pickTAPDStory and parseTAPDRecords first, since the proposed helpers wrap them, and check that the not-found error text stays byte-identical. Done means the existing tapd_*_test.go files still pass and the new tapd_record_fetch_test.go covers the helpers. A linked pull request (#423) is already open, so coordinate with its author before starting.

由索引模型根據 Issue 內容生成。

描述

现状问题

internal/tracker/service.go 中 ImportTAPDStory 与 ResyncTAPDIssue 各自内联了一份几乎相同的「读取单条 TAPD 记录」流程:

  1. 按 kind 选 *_get 工具,构造 proxy_execute_tool 参数(workspace_id / id / limit=1 / page=1 / fields)调用 MCP;
  2. parseTAPDRecords(raw, kind+"s") 解析后用 pickTAPDStory 挑出目标记录,找不到时返回 未找到 TAPD <标签> <ID>;
  3. 按 kind 用 if task / else if bug / else 分派到 upsertTAPDTask / upsertTAPDBug / upsertTAPDStory。

三段逻辑各写两遍(约 35 行重复),以后改参数或新增记录类型需要两处同步,容易漏改。

重构方案

在同一文件内抽出三个包内函数,两个导出方法改为调用它们:

  • callTAPDRecordGet(client, kind, workspaceID, id):只负责构造参数并调用 proxy_execute_tool,返回原始结果;
  • pickTAPDRecord(raw, kind, id):解析结果并挑出目标记录,未找到时返回与原来逐字一致的错误;
  • (s *Service) upsertTAPDByKind(...):按 kind 分派到现有的三个 upsert 方法。

调用失败时写入的同步日志(import_story / resync)仍留在各自方法里,日志内容、出错时机、返回值均不变。

影响范围

仅 internal/tracker/service.go 内部实现,外加新增一个单元测试文件;不改导出 API、不改行为、不改其他包。

验证方式

  • 新增 internal/tracker/tapd_record_fetch_test.go,覆盖 pickTAPDRecord 命中/未命中/解析失败与 upsertTAPDByKind 三种 kind 的分派结果;
  • 现有 tapd_import_test.go、tapd_resync_test.go、tapd_task_import_test.go 等保持通过;
  • gofmt、go vet ./internal/tracker/、go test ./internal/tracker/。
主要語言
Go
星號
141
分支
28
平均合併
1 天 15 小時
30 天內合併 PR
113

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

Tencent/LoopForge 的其他 Issue

查看 Tencent/LoopForge 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。