跳转到内容

cnb-rs pr view

cnb-rs pr view <NUMBER> [flags]

查看 Pull Request 详情:标题、状态、源/目标分支、作者、评审人、处理人、标签、可合并状态等元数据,附 PR 正文。

选项

  • <NUMBER>:PR 编号(必填)
  • --web:在浏览器中打开 PR 页面
  • --comments:追加展示 PR 上的评论列表(调 list_pull_comments);不带本 flag 不拉
  • --reviews:追加展示 PR 上的评审列表(调 list_pull_reviews);不带本 flag 不拉
  • --json:以 JSON 输出(合并 pull + assignees + comments + reviews 四个字段成单个对象,未请求部分返空数组)

继承的全局选项:

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

输出说明

表格字段顺序(仅在有信息时展示,避免空行噪音):

字段来源说明
编号Pull.number#N 格式
标题Pull.title
状态Pull.state + Pull.is_wipopen / closed / merged;WIP 时加 (WIP) 后缀
源分支Pull.head跨仓 PR 加 owner/repo:branch 前缀;剥掉 refs/heads/
目标分支Pull.base同上
作者Pull.author昵称 (username)
处理人list_pull_assignees逗号分隔
评审人Pull.reviewers用户 [评审状态],状态有 pending/approved/changes_requested 等
标签Pull.labels逗号分隔 name
可合并状态Pull.mergeable_statemergeable / checking / conflict / merged
阻塞原因Pull.blocked_on仅在非 unblocked 时显示(unblocked 是常态值,展示是噪音)
合并者Pull.merged_by仅 merged 时有值

正文 body 在表格下方单独打印(保留 markdown 原文,方便管道接 glow - 或保存到文件)。

示例

bash
# 查看 PR 详情
$ cnb-rs pr view 271
字段
编号          #271
标题          🔧 chore(release): 准备 v0.11.2 发版
状态          closed
源分支        wwvo/cnb-rs/cnb-rs:release/v0.11.2
目标分支      wwvo/cnb-rs/cnb-rs:main
作者          Cloud Native Build (OCI)
评审人        竹蜻蜓 (BambooCopter) [pending], illegal_name (illegal_name_cnb.by9cbmyhqda) [approved]
可合并状态    merged
合并者        illegal_name (illegal_name_cnb.by9cbmyhqda)

## 自动发版准备
...

# 浏览器打开
$ cnb-rs pr view 271 --web

# JSON 给脚本消费
$ cnb-rs --json pr view 271 | jq '.pull.state'
"closed"

# 把正文管道给 glow 渲染
$ cnb-rs pr view 271 | tail -n +N | glow -

评论 / 评审 追加 section输出格式

传了 --comments 后主表 + body 之后追加:

=== Comments (N) ===

[<id>] <author> · <created_at>
<body>

[<id>] ...

传了 --reviews 后追加:

=== Reviews (N) ===

<author> [<state>] · <created_at>
<body>

两个 flag 可同时传,只走一轮并发。

API 调用

步骤API方法说明
PR 元数据${API}/repos/{repo}/-/pulls/{n}GETPull 详情;始终发
处理人${API}/repos/{repo}/-/pulls/{n}/assigneesGETPull 缺 assignees 字段,始终发
评论(可选)${API}/repos/{repo}/-/pulls/{n}/commentsGET仅在传 --comments 时调
评审(可选)${API}/repos/{repo}/-/pulls/{n}/reviewsGET仅在传 --reviews 时调

所有请求用 tokio::join! 并发。任一步失败:assignees / comments / reviews 失败时降级为空列表不中断;get_pull 失败时直接 bail

Known limitations

  • 不显示时间字段(created_at / updated_at):get_pull 返回的 Pull 类型不含时间,要看时间用 cnb-rs pr list
  • 评论 section 不跳转到单条评论详情(也不需要):CNB 没有独立的 comment view URL 格式

另请参阅

Released under the MIT License.