【架构优化】从 githubCombinedChecks 中拆出 commit status/check runs 读取与整体状态汇总 githubChecksOverall

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

維護者通常 1 天內回覆

@fx-kurumi 已經在處理了。

開始於 2026年11月13日。

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

評估

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

研究方向

The work is confined to githubCombinedChecks in internal/httpapi/agent_tool_github.go, which should be split into githubCommitStatuses, githubCheckRuns and githubChecksOverall without changing URLs, warnings or outcome rules. Read that function and its caller githubPRStatus, then run go test ./internal/httpapi/ to get a baseline. Note that pull request #484 is already open against this issue, so check it before starting. Done means the existing tests pass and a new table-driven test covers githubChecksOverall.

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

描述

现状问题

internal/httpapi/agent_tool_github.go 中的 githubCombinedChecks 约 80 行,一个函数里依次做了三件事:

  1. 请求 commit status API、解析、追加结果和截断告警;
  2. 请求 check-runs API、解析(status/conclusion 取值)、追加结果和截断告警;
  3. 按 githubCheckOutcome 汇总 overall,并在有告警时把 none/success 降级为 unknown。

两段读取结构几乎一样,又和汇总逻辑写在同一个函数里,读起来要来回对照;汇总规则只能通过 mock HTTP 间接测试。

重构方案

在同文件内拆出三个包级函数,githubCombinedChecks 只负责按顺序调用并拼接结果:

  • githubCommitStatuses(ctx, client, token, path, sha) ([]githubCheckSummary, []string):读取 commit status;
  • githubCheckRuns(ctx, client, token, path, sha) ([]githubCheckSummary, []string):读取 check runs;
  • githubChecksOverall(checks, warnings) string:汇总整体状态。

请求 URL、告警文案、状态取值、汇总规则全部原样保留。

影响范围

仅 internal/httpapi/agent_tool_github.go;githubCombinedChecks 签名及唯一调用方 githubPRStatus 不变,对外行为不变。

验证方式

  • 新增 githubChecksOverall 的表驱动单元测试(none / success / pending / failure / 有告警降级 unknown / 失败不被告警覆盖);
  • 现有 githubCombinedChecks 相关测试保持通过;
  • gofmt、go vet ./internal/httpapi/、go test ./internal/httpapi/。
主要語言
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 摘要。