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

Abierto
#483 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@fx-kurumi ya está trabajando en esto.

Desde el 13/11/2026.

  • #484 de @fx-kurumi — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
18/100
Tipo de issue
Refactorización
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
go
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

现状问题

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/。
Lenguaje dominante
Go
Estrellas
141
Forks
28
Merge medio
1 d 15 h
PR fusionados (30 d)
113

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Tencent/LoopForge

Todos los issues de Tencent/LoopForge

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.