# gerrit-comment > Fetch and post Gerrit review comments (as JSON) for a given change URL, change number, or Change-Id. Use when you need real review feedback for code fixes or want to post automated review comments. - Author: yinshengkai - Repository: Gary-Hobson/skills - Version: 20260122211555 - Stars: 1 - Forks: 0 - Last Updated: 2026-02-06 - Source: https://github.com/Gary-Hobson/skills - Web: https://mule.run/skillshub/@@Gary-Hobson/skills~gerrit-comment:20260122211555 --- --- name: gerrit-comment description: Fetch and post Gerrit review comments (as JSON) for a given change URL, change number, or Change-Id. Use when you need real review feedback for code fixes or want to post automated review comments. --- ## Get Comments Fetch published review comments from a Gerrit change. ```bash python3 scripts/get_comments.py --change "" [--revision ""] [--all] ``` - `--change`: Full URL (e.g., `https://gerrit.example.com/c/repo/+/12345`), change number, or Change-Id - `--revision`: Optional. SHA, patch set number, or `current` - `--all`: Optional. Show all threads (default: only unresolved threads) ## Post Comments Post review comments to a Gerrit change. ```bash python3 scripts/post_comment.py --change "" [options] ``` ### Basic Options - `--change`: Required. Full URL, change number, or Change-Id - `--revision`: Optional. SHA, patch set number, or `current` - `--message`: Optional. Overall review message - `--tag`: Optional. Tag for the review (e.g., `autogenerated:ci`) ### Inline Comment Options - `--file`: File path for inline comment - `--line`: Line number (1-based) - `--range`: Range as JSON: `{"start_line":1,"start_character":0,"end_line":5,"end_character":10}` - `--reply-to`: Comment ID to reply to - `--unresolved`: Mark comment as unresolved (default for new comments) - `--resolved`: Mark comment as resolved ### Vote Options - `--labels`: Labels as JSON: `{"Code-Review": 1, "Verified": 1}` ### Batch Comments - `--comments-json`: JSON string or `@filepath` with batch comments ### Examples Post a simple review message: ```bash python3 scripts/post_comment.py --change 12345 --message "LGTM" ``` Post an inline comment: ```bash python3 scripts/post_comment.py --change 12345 --file "src/main.py" --line 10 --message "Consider using a constant here" ``` Post with vote: ```bash python3 scripts/post_comment.py --change 12345 --message "Approved" --labels '{"Code-Review": 1}' ``` Post batch comments from file: ```bash python3 scripts/post_comment.py --change 12345 --comments-json @review.json ``` Batch JSON format: ```json { "message": "Overall review message", "tag": "autogenerated:my-tool", "labels": {"Code-Review": 1}, "comments": { "src/main.py": [ {"line": 10, "message": "Comment 1"}, {"line": 20, "message": "Comment 2", "unresolved": true} ] } } ``` ## Fetch Code To fetch the code for a specific patch set: ```bash git fetch {REMOTE} refs/changes/{XX}/{CHANGE_NUMBER}/{PATCH_SET_NUMBER} ``` - XX is the last two digits of the change number (e.g., for 12345, XX = 45) - CHANGE_NUMBER is the full change number - PATCH_SET_NUMBER is the specific patch set number (use latest_patchset from get_comments output) ## Environment | Variable | Required | |----------|----------| | `GERRIT_USER` | Yes | | `GERRIT_HTTP_PASSWORD` | Yes | | `GERRIT_BASE_URL` | Only when using change number/ID | ## Output ### Get Comments Success ```json { "change": "12345", "latest_patchset": 3, "unresolved_only": true, "thread_count": 1, "threads": [ { "file": "path/to/file.c", "range": {"start_line": 10, "start_character": 0, "end_line": 10, "end_character": 5}, "line": 10, "unresolved": true, "updated": "2026-01-13 11:57:15.000000000", "comments": [ { "id": "...", "in_reply_to": null, "patch_set": 1, "author": "Alice", "message": "...", "updated": "...", "unresolved": true } ] } ] } ``` ### Post Comment Success ```json { "change": "12345", "revision": "current", "success": true, "response": {} } ``` ### Error ```json { "change": "12345", "revision": null, "error": {"type": "GerritError", "message": "..."} } ``` ## Dependency `pip3 install python-gerrit-api`