【架构优化】合并 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 摘要。