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

オープン
#422 コメント 0 件 リアクション 0 件 担当者 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時間
マージ済み PR(30日)
113

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Tencent/LoopForge のほかの issue

Tencent/LoopForge の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。