跳转到内容

cnb-rs pr review

cnb-rs pr review <NUMBER> [flags]

提交 PR 评审或回复已有评审。借鉴 gh pr review 的单命令 + mode flag 设计:--approve / --request-changes / --comment 三选一决定评审性质;或用 --reply-to <REVIEW_ID> 走独立的回复 endpoint。

动作选项(四选一互斥)

  • -a, --approve:批准 PR(event=approve);body 可选(与 gh pr review --approve 行为一致,空 body 也是合法批准)
  • -r, --request-changes:请求修改(event=request_changes);body 必填
  • -c, --comment:仅评论,不影响 PR 状态(event=comment);body 必填
  • --reply-to <REVIEW_ID>:回复某条已有评审;走独立 endpoint POST .../reviews/{review_id}/replies;body 必填

clap conflicts_with_all 在 flag 层校验互斥;违反时 exit 2 + 提示。

不传任何动作 flag 会被自己定义的校验拒绝 + exit 1。

body 选项

  • -b, --body <BODY>:评审正文;与 --body-file 互斥
  • -F, --body-file <FILE>:从文件读评审正文;- 表示从 stdin 读;与 --body 互斥

继承的全局选项:

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

输出约定

  • stderr
    • 新建评审:✓ 已提交 PR #N 评审(event=approve/comment/request_changes)
    • 回复评审:✓ 已回复 PR #N 评审 (review_id=...)
  • stdout:PR URL

示例

bash
# 批准(最简)
$ cnb-rs pr review 42 --approve
 已提交 PR #42 评审(event=approve)
https://cnb.cool/org/repo/-/pulls/42

# 批准 + 评语
$ cnb-rs pr review 42 -a -b "LGTM,CI 也过了,可以合"

# 请求修改
$ cnb-rs pr review 42 -r -b "请把 auth.rs 里的 token 改用环境变量读"

# 仅评论(不影响状态)
$ cnb-rs pr review 42 -c -b "顺便问一下,这个改动跟 #38 有冲突吗?"

# 从文件读 body(多行 markdown)
$ cnb-rs pr review 42 -r -F review_notes.md

# 回复已有评审
$ cnb-rs pr review 42 --reply-to 12345 -b "已修复,请重新评审"

# 互斥违反:clap 拒绝
$ cnb-rs pr review 42 -a -r
error: the argument '--approve' cannot be used with '--request-changes'

# 不传动作 flag:自定义错误
$ cnb-rs pr review 42
错误: 请指定评审动作:--approve / --request-changes / --comment / --reply-to <ID>

# request-changes 不带 body:自定义错误
$ cnb-rs pr review 42 -r
错误: 当前评审模式必须提供 body:用 -b "..." -F <FILE>`-F -` stdin 读)

API 调用

模式API方法
-a/-r/-c${API}/repos/{repo}/-/pulls/{n}/reviewsPOST,body { body, event }
--reply-to${API}/repos/{repo}/-/pulls/{n}/reviews/{review_id}/repliesPOST,body { body, reply_to_comment_id: null }

CNB 的 review 可以包含多条行级 comment,reply_to_comment_id 是回复 review 内某条 comment 的 ID;CLI 第一版不暴露这层,统一传 null 表示「回复整个 review」。

pr comment 的差别

  • pr comment 发的是普通评论(PR 整体的讨论区),不携带评审动作
  • pr review 发的是评审,会出现在 PR 的「Reviews」区,且 approve / request-changes 影响 PR 状态(受合并保护规则触发)

查看历史评审:留给后续 pr view --reviews(P2 阶段加)。

另请参阅

Released under the MIT License.