跳转到内容

cnb-rs issue comment

cnb-rs issue comment <NUMBER> [flags]

在 Issue 上添加一条评论;或用 --edit-last / --id <CID> 编辑已有评论。借鉴 gh issue comment 的单命令 + flag 设计,比 gh 多一个能力--id <CID> 可编辑任意 CID 的评论(gh 只能 --edit-last)。

历史:v0.13 ~ P0-5 之前,本命令是 issue comment {add | list | view | edit} 4 子命令组;P0-5 折叠为单命令。

列举评论:留给 issue view --comments(CLI 上单查罕见,列举走 view 扩展即可)。

CNB API 没有 delete_issue_comment,所以本命令不提供 --delete-last(与 gh issue comment 略有不同)。

选项

  • <NUMBER>:Issue 编号(必填)
  • -b, --body <BODY>:评论正文;与 --body-file 互斥
  • -F, --body-file <FILE>:从文件读评论正文;- 表示从 stdin 读;与 --body 互斥
  • --edit-last:编辑当前用户在该 Issue 上最近一条评论(按 created_at 取最新),找不到则报错
  • --id <COMMENT_ID>:编辑指定 ID 的评论;与 --edit-last 互斥;比 gh 多一个能力
  • --attach <FILE>:附件文件路径(仅新增评论模式下生效;--edit-last / --id 时传 --attach 会报错)

至少需要传 -b-F 之一,否则报错。

继承的全局选项:

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

输出约定

  • stderr
    • 新增:✓ 已在 Issue #N 上发表评论 (id=...)
    • 编辑:✓ 已编辑 Issue #N 上的评论 (id=...)
  • stdout:Issue URL(CNB Web 端评论锚点 URL 格式没在 API 暴露,先只给 Issue URL)

示例

bash
# 添加一条评论
$ cnb-rs issue comment 42 -b "已确认问题,正在修复"
 已在 Issue #42 上发表评论 (id=2055950878457462784)
https://cnb.cool/org/repo/-/issues/42

# 从文件读 body(多行 markdown)
$ cnb-rs issue comment 42 -F notes.md

# 从 stdin 读(适合 pipe)
$ echo "lgtm" | cnb-rs issue comment 42 -F -

# 附件上传
$ cnb-rs issue comment 42 -b "补一个 trace" --attach trace.log

# 编辑当前用户最近一条评论(typo 补救常用)
$ cnb-rs issue comment 42 --edit-last -b "(edited) 已确认问题"
 已编辑 Issue #42 上的评论 (id=2055950878457462784)

# 编辑指定 CID 的评论(比 gh 多一个能力)
$ cnb-rs issue comment 42 --id 2055886607480520704 -b "新内容"

# 不传 body 报错
$ cnb-rs issue comment 42
错误: 请通过 -b/--body -F/--body-file 提供评论正文

# --edit-last 与 --id 互斥(clap 拒绝)
$ cnb-rs issue comment 42 --edit-last --id 12345
error: the argument '--edit-last' cannot be used with '--id <COMMENT_ID>'

# --edit-last / --id 模式不能带 --attach
$ cnb-rs issue comment 42 --edit-last -b "x" --attach trace.log
错误: --edit-last 模式不支持 --attach(编辑已存在评论加附件不在本命令范围内)

API 调用

模式API方法
新增(默认)${API}/repos/{repo}/-/issues/{n}/commentsPOST
--edit-last 找最近${API}/user + ${API}/repos/{repo}/-/issues/{n}/commentsGET × 2(并发)
--edit-last patch${API}/repos/{repo}/-/issues/{n}/comments/{cid}PATCH
--id patch${API}/repos/{repo}/-/issues/{n}/comments/{cid}PATCH
--attach(CNB asset upload 三步)POST + PUT

--edit-last 总共 3 个 API 调用,前两个并发(tokio::join!)。

附件上传工作流(仅新增模式)

issue create --attach 不同:评论附件没有 asset-group 批量 API,每个文件单独调 POST /{repo}/-/issues/{n}/comment-{file|image}-asset-upload-url 申请 upload URL,之后步骤一致(PUT 到 OSS → 拿 asset_link → 追加到 body 末尾)。

任何一步附件上传失败会直接中断,评论 不会被创建。

迁移指南

从 P0-5 之前的 issue comment {add/list/view/edit} 子命令组

旧用法新用法
issue comment add 42 -c "x"issue comment 42 -b "x"(注意 -c-b
issue comment add 42 -c "x" --attach FILEissue comment 42 -b "x" --attach FILE
issue comment list 42issue view 42 --comments
issue comment view 42 <CID>issue view 42 --comments 后人眼找(CNB 无独立 comment view URL)
issue comment edit 42 <CID> -c "x"issue comment 42 --id <CID> -b "x"(cnb-rs 保留任意 CID 编辑能力,比 gh 多)

旧用法 fail 行为

bash
$ cnb-rs issue comment list 42
error: unexpected argument '42' found  # 因为 list 被认为是 NUMBER,42 被认为是位置参数多余

clap 直接拒绝,提示用户改用新单命令。

关联命令

issue close / issue reopen 也接受 -c "评论" 选项,在状态变更前先发评论;本命令是独立的「只发评论」单命令。

另请参阅

Released under the MIT License.