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

Đang mở
#422 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@fx-kurumi đang làm issue này rồi.

Từ ngày 13/11/2026.

  • #423 của @fx-kurumi — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
25/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
go
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

现状问题

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/。
Ngôn ngữ chính
Go
Star
141
Fork
28
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
113

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Tencent/LoopForge

Tất cả issue của Tencent/LoopForge

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.