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

Ouverte
#422 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@fx-kurumi y travaille déjà.

Depuis le 13/11/2026.

  • #423 par @fx-kurumi — ouverte

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
25/100
Type d'issue
Refactorisation
Clarté
Clairement spécifiée
Activité
À l'abandon
Stack technique
go
Domaine
backend

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

现状问题

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/。
Langage dominant
Go
Étoiles
141
Forks
28
Merge moyen
1 j 15 h
PR mergées (30 j)
113

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de Tencent/LoopForge

Toutes les issues de Tencent/LoopForge

Issues similaires

Plus d'issues Go

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.