已关闭
feat: gc repo branch-protection — 保护分支规则 CRUD(4 个 API 端点) #530
aflyingto创建于  8月11日关闭于  8月11日
aflyingto成员
8月11日 创建

背景

拆自 gh-parity 专项。gc 当前无保护分支配置功能,API 已就绪。对齐 gh ruleset 能力。

API 端点(4 个,均已就绪)

子命令 方法 路径 标题
gc repo branch-protection list GET /api/v5/repos/{owner}/{repo}/protect_branches 获取保护分支规则列表
gc repo branch-protection create PUT /api/v5/repos/{owner}/{repo}/branches/setting/new 新建保护分支规则
gc repo branch-protection update PUT /api/v5/repos/{owner}/{repo}/branches/{wildcard}/setting 更新保护分支规则
gc repo branch-protection delete DELETE /api/v5/repos/{owner}/{repo}/branches/{wildcard}/setting 删除保护分支规则

请求体字段

  • wildcard(string):分支通配符(如 main、release/*)
  • pusher:可推送者
  • merger:可合入者

命令接口

gc repo branch-protection list [-R owner/repo] [--json]
gc repo branch-protection create --wildcard <pattern> [--pusher <users>] [--merger <users>] [-R owner/repo] --yes
gc repo branch-protection update <wildcard> [--pusher <users>] [--merger <users>] [-R owner/repo] --yes
gc repo branch-protection delete <wildcard> [-R owner/repo] --yes

对齐 gh 参考

gh ruleset list/create/view/edit/delete

gh 用 ruleset 管理,GitCode 用保护分支规则,模型不同但功能对应。

验收标准

Refs gitcode-cli/cli#517

likedislike
Aaflyingto成员
8月11日 关联了里程碑:gh-parity: 全面对齐 gh CLI
Aaflyingto成员
8月11日 添加了label:enhancementscope/cli
aflyingto成员
8月11日 评论:

验证记录

验证版本: main (aaee4b7)
验证命令: gc repo branch-protection --help + 源码审查
验证结果:

  • gc repo branch-protection 命令不存在
  • 4 个 API 端点全部就绪:
    • GET /protect_branches(返回数组,17 字段:name/push_users/merge_users/developers_can_push 等)
    • PUT /branches/setting/new(body: wildcard/pusher/merger)
    • PUT /branches/{wildcard}/setting(body: pusher/merger)
    • DELETE /branches/{wildcard}/setting
  • 现有 类型不含保护规则字段,需定义新 类型
  • 方法已实现

结论: 确认功能缺失,4 个 CRUD 端点就绪,可实现。

likedislike
Aaflyingto成员
8月11日 关联了pull request:feat(repo): add gc repo branch-protection CRUD — list/create/update/delete
Aaflyingto成员
8月11日 关闭了 issue