Closed
refactor: 创建统一输出模块 pkg/output/ #126
aflyingtoAdd on  Apr 5Closed at  Apr 7
aflyingtoCollaborators
Apr 5 Create

问题描述

当前各命令直接使用 fmt.Fprintf 进行输出,代码分散且难以维护。需要创建统一的输出模块。

建议方案

创建 pkg/output/ 目录,包含以下文件:

pkg/output/
├── printer.go        # Printer 接口定义
├── table_printer.go  # 表格输出实现
├── json_printer.go   # JSON输出实现
├── text_printer.go   # 文本输出实现
└── template.go       # 模板输出支持

Printer 接口设计

package output

type Printer interface {
    PrintIssues(issues []*api.Issue) error
    PrintPRs(prs []*api.PullRequest) error
    PrintRepos(repos []*api.Repo) error
    PrintReleases(releases []*api.Release) error
}

type Options struct {
    Format     string // table, json, simple
    NoColor    bool
    TimeFormat string
}

好处

  1. 代码复用,减少重复
  2. 统一输出格式
  3. 便于添加新格式(如 CSV、YAML)
  4. 便于测试

优先级

高

likedislike
AaflyingtoCollaborators
Apr 5 Added label: status/verified,type/refactor
AaflyingtoCollaborators
Apr 7 Associated pull request
aflyingtoCollaborators
Apr 7 Comments:

阶段记录

  • 阶段: ready-for-review
  • 结论: PR #95 已覆盖 issue 126 的主目标:为 gc issue list 建立统一输出层,并把输出格式/时间格式能力收口到共享模块,当前进入独立执行主体评审。
  • 证据:
    • 关联 PR: !95
    • 提交: bce2821 feat: complete issue output contracts and view details
    • 验证: go test ./...、go build -o ./gc ./cmd/gc
    • 实际命令: ./gc issue list -R infra-test/gctest1 --limit 1 --json、./gc issue list -R infra-test/gctest1 --limit 1 --format json、./gc issue list -R infra-test/gctest1 --limit 1 --time-format relative
  • 下一步: 等待独立执行主体评审;如评审同意,再判断是否继续扩展到 issue/body/pr/release 等更多实体的统一 printer 抽象。

开发进度

  • 根因: 上一批实现把输出能力、help、文档和 issue/view 详情增强混在一起,且 issue list 的机器可消费入口出现漂移。
  • 主要修改: 新增 pkg/output 的最小共享实现,并让 issue list 通过同一套格式/时间渲染逻辑输出。
  • 测试: go test ./...
  • 实际命令验证: 同上
  • 安全影响: 无认证、权限或危险写路径变更
  • 风险或未覆盖项: 当前 PR 优先交付稳定 CLI 契约,不包含 issue 建议中更大范围的全实体 printer 重构。
  • 关联 PR: !95
likedislike
AaflyingtoCollaborators
Apr 7 Removed label: status/verified
AaflyingtoCollaborators
Apr 7 Added label: status/ready-for-review
AaflyingtoCollaborators
Apr 7 Added label: scope/docsscope/issue
AaflyingtoCollaborators
Apr 7 Close issue
AaflyingtoCollaborators
Apr 7 Added label: status/merged
AaflyingtoCollaborators
Apr 7 Removed label: status/ready-for-review
aflyingtoCollaborators
Apr 7 Comments:

已合入主干

  • 关联 PR: !95
  • 合并提交入口: !95
  • 合并时间: 2026-04-07 12:39 +08:00
  • 当前状态: 已合入 main,issue 关闭,标签已更新为 status/merged

说明: 本次以输出契约实现为主线完成交付,并在合并前吸收了主干最近的日期归一化/对齐修复。

likedislike
aflyingtoCollaborators
May 1 Comments:

作者自检

改动内容摘要

修复 issue prs --mode 1 三态渲染问题:

  1. CanMergeCheck 从 bool 改为 *bool
  2. 渲染逻辑修正:nil=unknown, true=can merge, false=cannot merge
  3. 文档添加三态含义说明

测试结果

go build ./api/... ./pkg/cmd/issue/prs/... ✓
go test ./pkg/cmd/issue/prs/... ✓

安全审查

  • ✓ 无安全风险,仅修改数据类型和渲染逻辑

文档同步

  • COMMANDS.md 已添加 --mode 1 mergeable 状态含义

风险评估

  • 风险等级: low
  • 理由:类型修改,无破坏性改动

状态

  • status/self-checked
likedislike
aflyingtoCollaborators
May 1 Comments:

多角色独立执行主体评审汇总

评审路径

标准 4 角色评审

第一轮评审结论

评审角色 结论 主要发现
代码审查 approved 类型修改正确,三态渲染正确
安全审查 approved 指针使用安全,nil 检查正确
测试审查 approved 测试全部通过(7个用例)
文档审查 approved 三态说明已添加

发现问题及修复情况

无问题发现。

总体评审结论

  • approved
  • 评审执行主体:4 个独立 Claude 子 Agent

评审角色:代码审查、安全审查、测试审查、文档审查

likedislike