arinhub-submit-code-review
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSubmit Code Review
提交代码评审
Submit a structured code review with line-specific comments to a GitHub pull request. Identifies issues in the current chat session or review file, checks for duplicate comments, and submits the review.
向GitHub拉取请求(pull request)提交带有行级特定注释的结构化代码评审。识别当前聊天会话或评审文件中的问题,检查重复注释,然后提交评审。
Input
输入
- PR number or URL (required): The pull request identifier. Accepts:
- Number:
123 - Hash-prefixed:
#123 - Full URL:
https://github.com/owner/repo/pull/123
- Number:
- Review file path (optional): Path to a review file produced by (e.g.,
arinhub-code-reviewer). If provided, issues are extracted from this file instead of the current chat session.~/.agents/arinhub/code-reviews/pr-code-review-my-app-123.md
- PR编号或URL(必填):拉取请求的标识符。支持:
- 编号:
123 - 带#前缀:
#123 - 完整URL:
https://github.com/owner/repo/pull/123
- 编号:
- 评审文件路径(可选):由生成的评审文件路径(例如
arinhub-code-reviewer)。如果提供此参数,将从该文件中提取问题,而非当前聊天会话。~/.agents/arinhub/code-reviews/pr-code-review-my-app-123.md
Procedure
流程
1. Resolve PR Identifier
1. 解析PR标识符
Extract the PR number from the user input. Strip any prefix or parse the number from a URL.
#PR_NUMBER=<extracted number>从用户输入中提取PR编号。去除前缀或从URL中解析编号。
#PR_NUMBER=<extracted number>2. Fetch PR Metadata
2. 获取PR元数据
Gather PR details:
bash
gh pr view $PR_NUMBER --json number,title,body,baseRefName,headRefName,files,url收集PR详细信息:
bash
gh pr view $PR_NUMBER --json number,title,body,baseRefName,headRefName,files,url3. Fetch Existing Review Comments
3. 获取现有评审注释
Retrieve all existing review comments to prevent duplication:
bash
gh api repos/{owner}/{repo}/pulls/$PR_NUMBER/comments --paginate --jq '.[] | {id, path, line, body, user: .user.login}'Also fetch top-level review bodies:
bash
gh api repos/{owner}/{repo}/pulls/$PR_NUMBER/reviews --paginate --jq '.[] | {id, body, state, user: .user.login}'检索所有现有评审注释以避免重复:
bash
gh api repos/{owner}/{repo}/pulls/$PR_NUMBER/comments --paginate --jq '.[] | {id, path, line, body, user: .user.login}'同时获取顶级评审内容:
bash
gh api repos/{owner}/{repo}/pulls/$PR_NUMBER/reviews --paginate --jq '.[] | {id, body, state, user: .user.login}'4. Get Issue List
4. 获取问题列表
Get a list of issues from one of these sources (in priority order):
- Review file: If a review file path is provided (e.g., from orchestrator), read the file and extract all issues from the
arinhub-code-reviewersection.## Issues - Current chat session: If no review file is specified, collect issues identified during the code review in the current chat session.
For each issue found, record:
- : The relative file path
path - : The specific line number in the new version of the file (must be within the diff hunk). For multi-line issues, this is the last line of the range.
line - (optional): The first line of a multi-line range. Only set when the issue spans more than one line.
start_line - : A concise, actionable comment explaining the issue
body - (optional): The replacement code that should replace the line(s) from
suggestion(orstart_line) throughline. Include this whenever you can propose a concrete fix. The suggestion content is the exact code that will replace the selected lines -- do not includelinefences here, they are added automatically in Step 7.```suggestion
从以下来源之一获取问题列表(按优先级排序):
- 评审文件:如果提供了评审文件路径(例如来自编排器),读取文件并从
arinhub-code-reviewer部分提取所有问题。## Issues - 当前聊天会话:如果未指定评审文件,收集当前聊天会话中代码评审过程中识别的问题。
对于每个找到的问题,记录:
- :相对文件路径
path - :文件新版本中的特定行号(必须在差异块范围内)。对于多行问题,这是范围的最后一行。
line - (可选):多行范围的第一行。仅当问题跨越多行时设置。
start_line - :简洁、可操作的问题说明注释
body - (可选):应替换从
suggestion(或start_line)到line的代码。只要能提出具体修复方案就包含此内容。建议内容是将替换选定行的精确代码——此处不要包含line标记,它们会在步骤7中自动添加。```suggestion
5. Deduplicate Comments
5. 去重注释
For each issue identified in Step 4, compare against existing comments from Step 3:
- Skip if an existing comment on the same and
path(or nearby range +/- 3 lines) already addresses the same concernline - Skip if the issue is already mentioned in any top-level review body
- Use semantic comparison, not exact string matching -- if the existing comment covers the same problem, even with different wording, skip the new comment
对于步骤4中识别的每个问题,与步骤3中的现有注释进行比较:
- 如果同一和
path(或附近±3行范围)的现有注释已解决相同问题,则跳过line - 如果问题已在任何顶级评审内容中提及,则跳过
- 使用语义比较,而非精确字符串匹配——如果现有注释涵盖相同问题,即使措辞不同,也跳过新注释
6. Decision Gate
6. 决策节点
- If no new issues remain after deduplication: Do not submit a review. Inform the user that no new issues were found beyond existing review comments.
- If new issues exist: Proceed to Step 7.
- 去重后无新问题:不要提交评审。告知用户除现有评审注释外未发现新问题。
- 存在新问题:继续执行步骤7。
7. Submit the Review
7. 提交评审
Submit a single review via the GitHub API. The review consists of one main comment () with individual inline comments () that appear as conversation threads anchored to specific lines in the diff.
bodycommentsPreflight validation checklist (run before submission):
- Validate JSON payload before sending (e.g., pipe the heredoc through to check syntax)
jq . >/dev/null - Ensure each comment has valid ,
path, andlineside: "RIGHT" - For multi-line comments, include and
start_linetogether withstart_side: "RIGHT"line - Confirm (and
linefor ranges) is inside the PR diff hunk for that filestart_line - If a suggestion is included, append it in using
bodyfences (do not pre-wrap suggestion content in fences earlier)```suggestion - Ensure suggestion replacement code preserves indentation and exact intended final content
- Use an empty suggestion block () only when the intent is to delete selected lines
```suggestion\n```
bash
gh api repos/{owner}/{repo}/pulls/$PR_NUMBER/reviews \
--method POST \
--input - <<'EOF'
{
"event": "APPROVE or COMMENT",
"body": "<main-review-comment>",
"comments": [
{
"path": "<file-path>",
"line": <line-number>,
"side": "RIGHT",
"body": "<thread-comment>\n\n```suggestion\n<replacement-code>\n```"
}
]
}
EOFFor multi-line suggestions, add and :
start_linestart_sidejson
{
"path": "<file-path>",
"start_line": <first-line>,
"line": <last-line>,
"start_side": "RIGHT",
"side": "RIGHT",
"body": "<thread-comment>\n\n```suggestion\n<replacement-code>\n```"
}If a comment has no suggestion (pure observation), omit the block from the body. Still include so that all comments are anchored to the new version of the file.
```suggestion ```"side": "RIGHT"Main review comment (): See main-review-comment.md for the full template and examples.
bodyThread comments (): See thread-comment.md for the full template and examples.
comments[].body通过GitHub API提交单个评审。评审包含一个主注释()和多个行内注释(),这些行内注释会作为对话线程锚定到差异中的特定行。
bodycomments提交前验证清单(提交前运行):
- 发送前验证JSON负载(例如通过检查语法)
jq . >/dev/null - 确保每个注释都有有效的、
path和lineside: "RIGHT" - 对于多行注释,将和
start_line与start_side: "RIGHT"一起包含line - 确认(以及多行范围的
line)在该文件的PR差异块内start_line - 如果包含建议,在中使用
body标记包裹(不要提前在建议内容外添加标记)```suggestion - 确保建议替换代码保留缩进和预期的最终内容
- 仅当意图是删除选定行时,使用空建议块()
```suggestion\n```
bash
gh api repos/{owner}/{repo}/pulls/$PR_NUMBER/reviews \
--method POST \
--input - <<'EOF'
{
"event": "APPROVE or COMMENT",
"body": "<main-review-comment>",
"comments": [
{
"path": "<file-path>",
"line": <line-number>,
"side": "RIGHT",
"body": "<thread-comment>\n\n```suggestion\n<replacement-code>\n```"
}
]
}
EOF对于多行建议,添加和:
start_linestart_sidejson
{
"path": "<file-path>",
"start_line": <first-line>,
"line": <last-line>,
"start_side": "RIGHT",
"side": "RIGHT",
"body": "<thread-comment>\n\n```suggestion\n<replacement-code>\n```"
}如果注释没有建议(仅观察),从body中省略块。仍需包含,以便所有注释都锚定到文件的新版本。
```suggestion ```"side": "RIGHT"主评审注释():完整模板和示例请参见main-review-comment.md。
body线程注释():完整模板和示例请参见thread-comment.md。
comments[].body8. Report Result
8. 报告结果
After submission, confirm to the user:
- Number of review comments submitted
- The PR URL for reference
- Brief list of issues flagged
If no review was submitted (Step 6), explain that no new issues were found beyond existing review comments.
提交后,向用户确认:
- 提交的评审注释数量
- 供参考的PR URL
- 标记的问题简要列表
如果未提交评审(步骤6),说明除现有评审注释外未发现新问题。
9. Extract Requirements Coverage
9. 提取需求覆盖情况
Look for a Requirements Coverage section in the same source used in Step 4:
- Review file: If a review file was used, look for a section and extract its full content.
## Requirements Coverage - Current chat session: If no review file was used, look for any Requirements Coverage report or coverage summary produced during the current chat session.
If no Requirements Coverage is found, skip to the end -- this step is optional.
在步骤4使用的同一来源中查找需求覆盖部分:
- 评审文件:如果使用了评审文件,查找部分并提取其全部内容。
## Requirements Coverage - 当前聊天会话:如果未使用评审文件,查找当前聊天会话中生成的任何需求覆盖报告或覆盖摘要。
如果未找到需求覆盖情况,直接结束——此步骤为可选。
10. Post Requirements Coverage Comment
10. 发布需求覆盖注释
This step runs only if Requirements Coverage was found in Step 9. It must be the very last action -- execute it after all other steps (including the review submission and result report) are complete.
Post the coverage report as a standalone PR comment:
bash
gh pr comment $PR_NUMBER --body "$(cat <<'EOF'
<coverage-content>
EOF
)"- Use the Requirements Coverage content exactly as found -- do not modify, summarize, or reformat it
- This comment is independent of the review; post it even if no review was submitted in Step 6
- This must be the very last API call in the entire procedure to ensure the coverage comment appears at the bottom of the PR conversation
仅当步骤9中找到需求覆盖情况时才执行此步骤。这必须是最后一个操作——在完成所有其他步骤(包括评审提交和结果报告)后执行。
将覆盖报告作为独立的PR注释发布:
bash
gh pr comment $PR_NUMBER --body "$(cat <<'EOF'
<coverage-content>
EOF
)"- 完全按原样使用需求覆盖内容——不要修改、总结或重新格式化
- 此注释独立于评审;即使步骤6中未提交评审,也要发布此注释
- 这必须是整个流程中的最后一个API调用,以确保覆盖注释显示在PR对话的底部
Important Notes
重要说明
- Use when no High Priority issues are found, otherwise use
APPROVE. Never useCOMMENTunless the user explicitly asksREQUEST_CHANGES - The field in review comments must reference a line that appears in the diff -- comments on unchanged lines will be rejected by the API
line - For multi-line suggestions, use and
start_linetogether to define the range being replaced; both must be within the diff hunkline - An empty suggestion block () means "delete these lines"
```suggestion\n``` - The content inside replaces the selected line(s) verbatim -- ensure correct indentation and formatting
```suggestion ``` - Never fabricate issues -- only flag genuine concerns backed by evidence in the code
- 当未发现高优先级问题时使用,否则使用
APPROVE。除非用户明确要求,否则永远不要使用COMMENTREQUEST_CHANGES - 评审注释中的字段必须引用差异中出现的行——对未更改行的注释会被API拒绝
line - 对于多行建议,同时使用和
start_line定义要替换的范围;两者都必须在差异块内line - 空建议块()表示“删除这些行”
```suggestion\n``` - 内的内容会逐字替换选定行——确保缩进和格式正确
```suggestion ``` - 不要编造问题——仅标记有代码证据支持的真实问题