跳转到内容

cnb-rs pr close

cnb-rs pr close <NUMBER>... [flags]

关闭 Pull Request(不合并、不删分支)。支持批量编号,逐个处理;任一失败累计计数,最后以非零退出码结束(与 cnb-rs issue close 一致的批量语义)。

选项

  • <NUMBER>...:PR 编号(必填,至少一个);支持空格分隔或逗号分隔多个编号
  • -c, --comment <STRING>:附一条关闭评论(可选)。提供后会在每个 PR 关闭前先 POST 评论,贴近 gh pr close <N> -c "..." 习惯
    • 评论失败不阻断关闭(只在 stderr warn),避免「评论失败连带 PR 也关不了」诡异

继承的全局选项:

  • --repo <REPO>:指定仓库路径(格式:group/repo
  • --domain <DOMAIN>:指定目标域名(默认:cnb.cool

输出约定

  • stderr:每成功一个打 ✓ 已关闭 PR #N;失败的打 ✗ 关闭 PR #N 失败:<err>;最后若有失败再打 错误: K 个 PR 关闭失败
  • stdout:每个成功关闭的 PR 输出一行完整 URL,方便 cnb-rs pr close 42 43 | xargs ... 之类管道
  • 退出码:全部成功 → 0;任一失败 → 1

示例

bash
# 关闭单个 PR
$ cnb-rs pr close 42
 已关闭 PR #42
https://cnb.cool/org/repo/-/pulls/42

# 空格分隔批量关闭
$ cnb-rs pr close 42 43 44

# 逗号分隔(与空格效果等价)
$ cnb-rs pr close 42,43,44

# 附关闭评论(贴近 gh)
$ cnb-rs pr close 42 -c "feature 取消,合进仓库意义不大"
 已关闭 PR #42
https://cnb.cool/org/repo/-/pulls/42

# 部分失败:成功的写 URL 到 stdout,失败的写错误到 stderr,整体 exit 1
$ cnb-rs pr close 42 99999
 已关闭 PR #42
https://cnb.cool/org/repo/-/pulls/42
 关闭 PR #99999 失败:{"errcode":404,"errmsg":"不存在"}
错误: 1 PR 关闭失败
$ echo $?
1

API 调用

步骤API方法说明
发评论(可选)${API}/repos/{repo}/-/pulls/{n}/commentsPOST仅在传了 -c 时调;失败不阻断关闭
关闭 PR${API}/repos/{repo}/-/pulls/{n}PATCHbody { state: "closed" },逐个 PR 单独调一次

Known limitations

  • 不支持 --reason(CNB PR API 没有显式 state_reason 字段,issue 才有 completed / not_planned 区分)

迁移指南(从 pr update --state closed

pr update --state flag 已在 P1 阶段移除(P0-2 时已加 deprecation warning)。请改用:

bash
# 旧
$ cnb-rs pr update 42 --state closed

# 新
$ cnb-rs pr close 42

另请参阅

Released under the MIT License.