跳转到内容

cnb-rs issue comment ​

cnb-rs issue comment <NUMBER> [flags]

在 Issue 上添加一条评论;用 --view <COMMENT_ID> 查看单条评论;或用 --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;查看单条评论:使用 issue comment <NUMBER> --view <COMMENT_ID>。

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

选项 ​

  • <NUMBER>:Issue 编号(必填)
  • --view <COMMENT_ID>:查看指定 ID 的评论;与 --body / --body-file / --edit-last / --id / --work-mode / --attach 互斥
  • -b, --body <BODY>:评论正文;与 --body-file 互斥
  • -F, --body-file <FILE>:从文件读评论正文;- 表示从 stdin 读;与 --body 互斥
  • --edit-last:编辑当前用户在该 Issue 上最近一条评论(按 created_at 取最新),找不到则报错
  • --id <COMMENT_ID>:编辑指定 ID 的评论;与 --edit-last 互斥;比 gh 多一个能力
  • --work-mode:开启 NPC 工作模式(评论中需 @ NPC;授予其写代码 / 推分支 / 发 PR 权限,需开发者及以上权限);仅新增评论时可用,与 --view / --edit-last / --id 互斥
  • --attach <FILE>:附件文件路径(仅新增评论模式下生效;--edit-last / --id 时传 --attach 会报错)

新增或编辑评论时至少需要传 -b 或 -F 之一;--view 模式不需要正文。

继承的全局选项:

  • --repo <REPO>:指定仓库路径(格式:group/repo)
  • --domain <DOMAIN>:指定目标域名(默认:cnb.cool)
  • --json:--view 模式原样输出 IssueComment JSON

输出约定 ​

  • 新增 / 编辑:stderr 输出结果提示,stdout 输出 Issue URL
    • 新增:✓ 已在 Issue #N 上发表评论 (id=...)
    • 编辑:✓ 已编辑 Issue #N 上的评论 (id=...)
  • 查看:stdout 输出作者、创建时间、更新时间、正文,以及非空的 statuses;--json 时原样输出 IssueComment JSON

示例 ​

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

# @ NPC 并开启工作模式
$ cnb-rs issue comment 42 --work-mode -b "@npc/CodeBuddy(deepseek-v4.1-flash) 请修复这个问题并发起 PR"

# 从文件读 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

# 查看单条评论(加 --json 可原样输出 IssueComment JSON)
$ cnb-rs issue comment 42 --view 2055950878457462784
作者: alice
创建时间: 2026-09-16T10:00:00Z
更新时间: 2026-09-16T10:05:00Z

已确认问题,正在修复

# 编辑当前用户最近一条评论(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
--view${API}/repos/{repo}/-/issues/{n}/comments/{cid}GET
--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 comment 42 --view <CID>
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.