You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过API(HTTP/REST或SSH)丢弃Gerrit特定评审的草稿评论?

Alright, let’s walk through exactly how to discard draft review comments in Gerrit using either the HTTP REST API or SSH API—no web interface clicks needed, just clean command-line or scriptable calls.

Using the HTTP REST API

First, you’ll need to get the ID of the draft comment you want to delete. Gerrit’s REST API makes this straightforward:

  1. Fetch all draft comments for a specific change
    Send a GET request to the draft comments endpoint for your target change. Replace {change-id} with either the numeric change ID, change number, or full reference (like refs/changes/45/12345/3).

    curl -u your-username:your-auth-token https://your-gerrit-domain.com/a/changes/{change-id}/draft_comments
    
    • Note: Use an HTTP auth token instead of your password if you have 2FA enabled—you can generate one in Gerrit’s settings under HTTP Credentials.
    • The response will be a JSON array of draft comments, each with an id field (this is the value you’ll need for deletion).
  2. Delete the specific draft comment
    Use a DELETE request targeting the draft comment’s ID. Replace {draft-comment-id} with the ID you pulled from the previous step:

    curl -X DELETE -u your-username:your-auth-token https://your-gerrit-domain.com/a/changes/{change-id}/draft_comments/{draft-comment-id}
    

    A successful deletion will return a 204 No Content status code.

Using the SSH API

If you prefer using Gerrit’s SSH interface (which is often more straightforward for command-line workflows), here’s how to do it:

  1. List draft comments for the change
    Connect to your Gerrit instance via SSH and run the draft-comments list command with your target change ID:

    ssh -p 29418 your-username@your-gerrit-domain.com gerrit draft-comments list {change-id}
    

    This will output a list of draft comments with their IDs, along with details like the file path and comment text.

  2. Delete the draft comment
    Use the draft-comments delete command with both the change ID and draft comment ID:

    ssh -p 29418 your-username@your-gerrit-domain.com gerrit draft-comments delete {change-id} {draft-comment-id}
    

    You’ll get a confirmation message like Deleted draft comment {draft-comment-id} from change {change-id} if the operation succeeds.

Quick Notes

  • Make sure you have the necessary permissions: you can only delete draft comments that you created, or if you have administrative privileges for the change.
  • For both APIs, {change-id} can be any valid identifier for the review (numeric ID, change number, or full ref path—Gerrit will resolve it automatically).

内容的提问来源于stack exchange,提问作者sorin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 11:43:13