attach-review-to-pr
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHow to Attach Line-Specific Review Comments to Pull Requests
如何为拉取请求添加特定行的评审评论
This guide explains how to add line-specific review comments to pull requests using the GitHub CLI () API or if it not available, similar to how the GitHub UI allows commenting on specific lines of code.
ghmcp__github_inline_comment__create_inline_comment本指南说明如何使用GitHub CLI()API或(当前者不可用时)为拉取请求添加特定行的评审评论,这与GitHub UI中针对代码特定行添加评论的方式类似。
ghmcp__github_inline_comment__create_inline_commentPreferred Approach: Using MCP GitHub Tools
首选方法:使用MCP GitHub工具
If available, use the MCP tool for posting line-specific inline comments on pull requests. This approach provides better integration with GitHub's UI and is the recommended method.
mcp__github_inline_comment__create_inline_commentFallback: If the MCP tool is not available, use the GitHub CLI () API methods described below:
gh- For single comments: Use the endpoint (see Adding a Single Line-Specific Comment)
/comments - For multiple comments: Use the endpoint (see Adding Multiple Line-Specific Comments Together)
/reviews
如果可用,请使用 MCP工具在拉取请求上发布特定行的内联评论。此方法与GitHub UI的集成度更高,是推荐的方式。
mcp__github_inline_comment__create_inline_comment备选方案:如果MCP工具不可用,请使用以下GitHub CLI()API方法:
gh- 添加单个评论:使用端点(参见添加单个特定行评论)
/comments - 添加多个评论:使用端点(参见批量添加多个特定行评论)
/reviews
Overview
概述
While provides basic review functionality (approve, request changes, general comments), it does not support line-specific comments directly. To add comments on specific lines of code, you must use the lower-level command to call GitHub's REST API directly.
gh pr reviewgh api虽然提供了基础的评审功能(批准、请求修改、通用评论),但它不直接支持特定行评论。要在代码的特定行添加评论,必须使用更底层的命令直接调用GitHub的REST API。
gh pr reviewgh apiPrerequisites
前提条件
-
GitHub CLI installed and authenticated:bash
gh auth status -
Access to the repository and pull request you want to review
-
已安装并完成认证的GitHub CLI:bash
gh auth status -
拥有目标仓库和拉取请求的访问权限
Understanding GitHub's Review Comment System
理解GitHub的评审评论系统
GitHub has two types of PR comments:
- Issue Comments - General comments on the PR conversation
- Review Comments - Line-specific comments on code changes
Review comments can be added in two ways:
- Single comment - Using the endpoint
/pulls/{pr}/comments - Review with multiple comments - Using the endpoint
/pulls/{pr}/reviews
GitHub有两种类型的PR评论:
- 议题评论 - 针对PR对话的通用评论
- 评审评论 - 针对代码变更的特定行评论
评审评论可以通过两种方式添加:
- 单个评论 - 使用端点
/pulls/{pr}/comments - 包含多个评论的评审 - 使用端点
/pulls/{pr}/reviews
Adding a Single Line-Specific Comment
添加单个特定行评论
Basic Syntax
基本语法
bash
gh api repos/{owner}/{repo}/pulls/{pr_number}/comments \
-f body='Your comment text here' \
-f commit_id='<commit-sha>' \
-f path='path/to/file.js' \
-F line=42 \
-f side='RIGHT'bash
gh api repos/{owner}/{repo}/pulls/{pr_number}/comments \
-f body='你的评论内容' \
-f commit_id='<commit-sha>' \
-f path='path/to/file.js' \
-F line=42 \
-f side='RIGHT'Parameters Explained
参数说明
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | Yes | The text of the review comment (supports Markdown) |
| string | Yes | The SHA of the commit to comment on |
| string | Yes | Relative path to the file being commented on |
| integer | Yes | The line number in the diff (use |
| string | Yes | |
| integer | No | For multi-line comments, the starting line |
| string | No | For multi-line comments, the starting side |
| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| string | 是 | 评审评论的文本内容(支持Markdown) |
| string | 是 | 要评论的提交SHA值 |
| string | 是 | 被评论文件的相对路径 |
| integer | 是 | 差异中的行号(整数需使用 |
| string | 是 | |
| integer | 否 | 多行评论的起始行 |
| string | 否 | 多行评论的起始侧 |
Parameter Flags
参数标志
- (--field) - For string values
-f - (--field) - For integer values (note the capital F)
-F
- (--field)- 用于字符串值
-f - (--field)- 用于整数值(注意大写F)
-F
Complete Example
完整示例
bash
undefinedbash
undefinedFirst, get the latest commit SHA for the PR
首先获取PR的最新提交SHA值
gh api repos/NeoLabHQ/learning-platform-app/pulls/4 --jq '.head.sha'
gh api repos/NeoLabHQ/learning-platform-app/pulls/4 --jq '.head.sha'
Then add your comment
然后添加评论
gh api repos/NeoLabHQ/learning-platform-app/pulls/4/comments
-f body='Consider adding error handling here. Should we confirm the lesson was successfully marked as completed before navigating away?'
-f commit_id='e152d0dd6cf498467eadbeb638bf05abe11c64d4'
-f path='src/components/LessonNavigationButtons.tsx'
-F line=26
-f side='RIGHT'
-f body='Consider adding error handling here. Should we confirm the lesson was successfully marked as completed before navigating away?'
-f commit_id='e152d0dd6cf498467eadbeb638bf05abe11c64d4'
-f path='src/components/LessonNavigationButtons.tsx'
-F line=26
-f side='RIGHT'
undefinedgh api repos/NeoLabHQ/learning-platform-app/pulls/4/comments
-f body='考虑在此处添加错误处理。我们是否应该在跳转前确认课程已成功标记为完成?'
-f commit_id='e152d0dd6cf498467eadbeb638bf05abe11c64d4'
-f path='src/components/LessonNavigationButtons.tsx'
-F line=26
-f side='RIGHT'
-f body='考虑在此处添加错误处理。我们是否应该在跳转前确认课程已成功标记为完成?'
-f commit_id='e152d0dd6cf498467eadbeb638bf05abe11c64d4'
-f path='src/components/LessonNavigationButtons.tsx'
-F line=26
-f side='RIGHT'
undefinedUnderstanding Line Numbers
理解行号
The parameter refers to the position in the diff, not the absolute line number in the file:
line- For new files: Line numbers match the file's line numbers
- For modified files: Use the line number as it appears in the "Files changed" tab
- For multi-line comments: Use and
start_lineto specify the rangeline
line- 新文件:行号与文件中的行号一致
- 修改的文件:使用"文件变更"标签中显示的行号
- 多行评论:使用和
start_line指定范围line
Response
响应
On success, returns a JSON object with comment details:
json
{
"id": 2532291222,
"pull_request_review_id": 3470545909,
"path": "src/components/LessonNavigationButtons.tsx",
"line": 26,
"body": "Consider adding error handling here...",
"html_url": "https://github.com/NeoLabHQ/learning-platform-app/pull/4#discussion_r2532291222",
"created_at": "2025-11-16T22:40:46Z"
}成功时,返回包含评论详情的JSON对象:
json
{
"id": 2532291222,
"pull_request_review_id": 3470545909,
"path": "src/components/LessonNavigationButtons.tsx",
"line": 26,
"body": "Consider adding error handling here...",
"html_url": "https://github.com/NeoLabHQ/learning-platform-app/pull/4#discussion_r2532291222",
"created_at": "2025-11-16T22:40:46Z"
}Adding Multiple Line-Specific Comments Together
批量添加多个特定行评论
To add multiple comments across different files in a single review, use the endpoint with JSON input.
/reviews要在一次评审中为不同文件添加多个评论,请使用端点并传入JSON输入。
/reviewsWhy Use Reviews for Multiple Comments?
为何使用评审端点添加多个评论?
- Atomic operation - All comments are added together
- Single notification - Doesn't spam with multiple notifications
- Better UX - Appears as one cohesive review
- Same mechanism as GitHub UI - "Start a review" → "Finish review"
- 原子操作 - 所有评论同时添加
- 单一通知 - 不会发送多条通知造成骚扰
- 更好的用户体验 - 显示为一个连贯的评审
- 与GitHub UI机制一致 - "开始评审" → "完成评审"
Basic Syntax
基本语法
bash
cat <<'EOF' | gh api repos/{owner}/{repo}/pulls/{pr_number}/reviews --input -
{
"event": "COMMENT",
"body": "Overall review summary (optional)",
"comments": [
{
"path": "file1.tsx",
"body": "Comment on file 1",
"side": "RIGHT",
"line": 15
},
{
"path": "file2.tsx",
"body": "Comment on file 2",
"side": "RIGHT",
"line": 30
}
]
}
EOFbash
cat <<'EOF' | gh api repos/{owner}/{repo}/pulls/{pr_number}/reviews --input -
{
"event": "COMMENT",
"body": "整体评审摘要(可选)",
"comments": [
{
"path": "file1.tsx",
"body": "针对文件1的评论",
"side": "RIGHT",
"line": 15
},
{
"path": "file2.tsx",
"body": "针对文件2的评论",
"side": "RIGHT",
"line": 30
}
]
}
EOFReview Event Types
评审事件类型
| Event | Description | When to Use |
|---|---|---|
| General review comment | Just leaving feedback without approval |
| Approve the PR | Changes look good, ready to merge |
| Request changes | Issues that must be fixed before merge |
| 事件 | 描述 | 使用场景 |
|---|---|---|
| 通用评审评论 | 仅留下反馈,不进行批准 |
| 批准PR | 变更符合要求,可合并 |
| 请求修改 | 存在必须修复的问题才能合并 |
Complete Example
完整示例
bash
cat <<'EOF' | gh api repos/NeoLabHQ/learning-platform-app/pulls/4/reviews --input -
{
"event": "COMMENT",
"body": "Testing multiple line-specific comments via gh api",
"comments": [
{
"path": "src/components/CourseCard.tsx",
"body": "Test comment generated by Claude",
"side": "RIGHT",
"line": 15
},
{
"path": "src/components/CourseProgressWidget.tsx",
"body": "Test comment generated by Claude",
"side": "RIGHT",
"line": 30
},
{
"path": "src/components/LessonProgressTracker.tsx",
"body": "Test comment generated by Claude",
"side": "RIGHT",
"line": 20
}
]
}
EOFbash
cat <<'EOF' | gh api repos/NeoLabHQ/learning-platform-app/pulls/4/reviews --input -
{
"event": "COMMENT",
"body": "通过gh api测试多个特定行评论",
"comments": [
{
"path": "src/components/CourseCard.tsx",
"body": "由Claude生成的测试评论",
"side": "RIGHT",
"line": 15
},
{
"path": "src/components/CourseProgressWidget.tsx",
"body": "由Claude生成的测试评论",
"side": "RIGHT",
"line": 30
},
{
"path": "src/components/LessonProgressTracker.tsx",
"body": "由Claude生成的测试评论",
"side": "RIGHT",
"line": 20
}
]
}
EOFResponse
响应
json
{
"id": 3470546747,
"state": "COMMENTED",
"html_url": "https://github.com/NeoLabHQ/learning-platform-app/pull/4#pullrequestreview-3470546747",
"submitted_at": "2025-11-16T22:42:43Z",
"commit_id": "e152d0dd6cf498467eadbeb638bf05abe11c64d4"
}json
{
"id": 3470546747,
"state": "COMMENTED",
"html_url": "https://github.com/NeoLabHQ/learning-platform-app/pull/4#pullrequestreview-3470546747",
"submitted_at": "2025-11-16T22:42:43Z",
"commit_id": "e152d0dd6cf498467eadbeb638bf05abe11c64d4"
}Common Issues and Solutions
常见问题及解决方案
Issue 1: "user_id can only have one pending review per pull request"
问题1:"user_id can only have one pending review per pull request"
Error Message:
gh: Validation Failed (HTTP 422)
{"message":"Validation Failed","errors":[{"resource":"PullRequestReview","code":"custom","field":"user_id","message":"user_id can only have one pending review per pull request"}]}Cause: GitHub only allows one pending (unsubmitted) review per user per PR. If you previously started a review through the UI or API and didn't submit it, it blocks new review creation.
Solution 1: Submit the pending review
bash
undefined错误信息:
gh: Validation Failed (HTTP 422)
{"message":"Validation Failed","errors":[{"resource":"PullRequestReview","code":"custom","field":"user_id","message":"user_id can only have one pending review per pull request"}]}原因: GitHub只允许每个用户针对每个PR存在一个待处理(未提交)的评审。如果您之前通过UI或API启动了评审但未提交,会阻止创建新的评审。
解决方案1:提交待处理的评审
bash
undefinedCheck for pending reviews
检查待处理的评审
gh api repos/{owner}/{repo}/pulls/{pr_number}/reviews | jq '.[] | select(.state=="PENDING")'
gh api repos/{owner}/{repo}/pulls/{pr_number}/reviews | jq '.[] | select(.state=="PENDING")'
Submit it through the UI or ask the user to submit it
通过UI提交,或让用户自行提交
**Solution 2: Use the single comment endpoint instead**
```bash
**解决方案2:改用单个评论端点**
```bashAdd individual comments without creating a review
添加单个评论,无需创建评审
gh api repos/{owner}/{repo}/pulls/{pr_number}/comments
-f body='Comment text'
-f commit_id='<sha>'
-f path='file.tsx'
-F line=26
-f side='RIGHT'
-f body='Comment text'
-f commit_id='<sha>'
-f path='file.tsx'
-F line=26
-f side='RIGHT'
undefinedgh api repos/{owner}/{repo}/pulls/{pr_number}/comments
-f body='评论内容'
-f commit_id='<sha>'
-f path='file.tsx'
-F line=26
-f side='RIGHT'
-f body='评论内容'
-f commit_id='<sha>'
-f path='file.tsx'
-F line=26
-f side='RIGHT'
undefinedIssue 2: Array syntax not working with --raw-field
问题2:数组语法无法与--raw-field一起使用
Failed Attempt:
bash
undefined失败尝试:
bash
undefinedThis does NOT work - GitHub API receives an object, not an array
此方法无效 - GitHub API接收的是对象而非数组
gh api repos/{owner}/{repo}/pulls/{pr}/reviews
--raw-field 'comments[0][path]=file1.tsx'
--raw-field 'comments[0][line]=15'
--raw-field 'comments[1][path]=file2.tsx'
--raw-field 'comments[1][line]=30'
--raw-field 'comments[0][path]=file1.tsx'
--raw-field 'comments[0][line]=15'
--raw-field 'comments[1][path]=file2.tsx'
--raw-field 'comments[1][line]=30'
**Error:**
Invalid request. For 'properties/comments', {"0" => {...}, "1" => {...}} is not an array.
**Solution:** Use JSON input via heredoc:
```bash
cat <<'EOF' | gh api repos/{owner}/{repo}/pulls/{pr}/reviews --input -
{
"comments": [...]
}
EOFgh api repos/{owner}/{repo}/pulls/{pr}/reviews
--raw-field 'comments[0][path]=file1.tsx'
--raw-field 'comments[0][line]=15'
--raw-field 'comments[1][path]=file2.tsx'
--raw-field 'comments[1][line]=30'
--raw-field 'comments[0][path]=file1.tsx'
--raw-field 'comments[0][line]=15'
--raw-field 'comments[1][path]=file2.tsx'
--raw-field 'comments[1][line]=30'
**错误:**
Invalid request. For 'properties/comments', {"0" => {...}, "1" => {...}} is not an array.
**解决方案:** 使用 heredoc 传入JSON输入:
```bash
cat <<'EOF' | gh api repos/{owner}/{repo}/pulls/{pr}/reviews --input -
{
"comments": [...]
}
EOFIssue 3: Invalid line number
问题3:无效行号
Error Message:
Pull request review thread line must be part of the diffCause: The line number doesn't exist in the diff for this file.
Solutions:
- Verify the file was actually changed in this PR
- Check the "Files changed" tab to see actual line numbers in the diff
- Ensure you're using the correct (the latest commit in the PR)
commit_id
错误信息:
Pull request review thread line must be part of the diff原因: 该行号不存在于该文件的差异中。
解决方案:
- 验证该文件是否确实在此PR中被修改
- 查看"文件变更"标签,确认差异中的实际行号
- 确保使用了正确的(PR中的最新提交)
commit_id
Issue 4: Wrong commit_id
问题4:错误的commit_id
Error Message:
commit_sha is not part of the pull requestSolution: Get the latest commit SHA:
bash
gh api repos/{owner}/{repo}/pulls/{pr_number} --jq '.head.sha'错误信息:
commit_sha is not part of the pull request解决方案: 获取最新的提交SHA值:
bash
gh api repos/{owner}/{repo}/pulls/{pr_number} --jq '.head.sha'Best Practices
最佳实践
1. Get PR Information First
1. 先获取PR信息
Before adding comments, gather necessary information:
bash
undefined添加评论前,收集必要的信息:
bash
undefinedGet PR details
获取PR详情
gh pr view {pr_number} --json headRefOid,files
gh pr view {pr_number} --json headRefOid,files
Or use the API
或使用API
gh api repos/{owner}/{repo}/pulls/{pr_number} --jq '{commit: .head.sha, files: [.changed_files]}'
gh api repos/{owner}/{repo}/pulls/{pr_number} --jq '{commit: .head.sha, files: [.changed_files]}'
List files changed
列出变更的文件
gh api repos/{owner}/{repo}/pulls/{pr_number}/files --jq '.[] | {filename: .filename, additions: .additions, deletions: .deletions}'
undefinedgh api repos/{owner}/{repo}/pulls/{pr_number}/files --jq '.[] | {filename: .filename, additions: .additions, deletions: .deletions}'
undefined2. Check for Pending Reviews
2. 检查待处理评审
bash
undefinedbash
undefinedCheck if you have a pending review
检查是否存在待处理的评审
gh api repos/{owner}/{repo}/pulls/{pr_number}/reviews
--jq '.[] | select(.state=="PENDING" and .user.login=="YOUR_USERNAME")'
--jq '.[] | select(.state=="PENDING" and .user.login=="YOUR_USERNAME")'
undefinedgh api repos/{owner}/{repo}/pulls/{pr_number}/reviews
--jq '.[] | select(.state=="PENDING" and .user.login=="YOUR_USERNAME")'
--jq '.[] | select(.state=="PENDING" and .user.login=="YOUR_USERNAME")'
undefined3. Use Meaningful Comment Text
3. 使用有意义的评论内容
- Be specific and constructive
- Reference documentation or best practices
- Suggest alternatives when requesting changes
- Use code blocks for code suggestions:
markdown
Consider using async/await:
\`\`\`typescript
async function getData() {
const result = await fetch(url);
return result.json();
}
\`\`\`- 具体且具有建设性
- 参考文档或最佳实践
- 请求修改时提供替代方案
- 使用代码块给出代码建议:
markdown
考虑使用async/await:
\`\`\`typescript
async function getData() {
const result = await fetch(url);
return result.json();
}
\`\`\`4. Batch Related Comments
4. 批量处理相关评论
Use the review endpoint to group related comments:
- All comments for a single file/area
- All comments for a specific concern (security, performance, etc.)
- Complete review session
使用评审端点对相关评论进行分组:
- 单个文件/区域的所有评论
- 针对特定关注点(安全、性能等)的所有评论
- 完整的评审会话
5. Choose the Right Event Type
5. 选择正确的事件类型
bash
undefinedbash
undefinedFor feedback during development
开发过程中的反馈
"event": "COMMENT"
"event": "COMMENT"
When approving
批准时
"event": "APPROVE"
"event": "APPROVE"
When blocking merge
阻止合并时
"event": "REQUEST_CHANGES"
undefined"event": "REQUEST_CHANGES"
undefinedWorkflow Examples
工作流示例
Example 1: Quick Single Comment
示例1:快速添加单个评论
bash
#!/bin/bash
OWNER="NeoLabHQ"
REPO="learning-platform-app"
PR=4bash
#!/bin/bash
OWNER="NeoLabHQ"
REPO="learning-platform-app"
PR=4Get latest commit
获取最新提交
COMMIT=$(gh api repos/$OWNER/$REPO/pulls/$PR --jq '.head.sha')
COMMIT=$(gh api repos/$OWNER/$REPO/pulls/$PR --jq '.head.sha')
Add comment
添加评论
gh api repos/$OWNER/$REPO/pulls/$PR/comments
-f body='Consider extracting this into a separate function for better testability'
-f commit_id="$COMMIT"
-f path='src/utils/validation.ts'
-F line=45
-f side='RIGHT'
-f body='Consider extracting this into a separate function for better testability'
-f commit_id="$COMMIT"
-f path='src/utils/validation.ts'
-F line=45
-f side='RIGHT'
undefinedgh api repos/$OWNER/$REPO/pulls/$PR/comments
-f body='考虑将此提取为单独的函数,以提高可测试性'
-f commit_id="$COMMIT"
-f path='src/utils/validation.ts'
-F line=45
-f side='RIGHT'
-f body='考虑将此提取为单独的函数,以提高可测试性'
-f commit_id="$COMMIT"
-f path='src/utils/validation.ts'
-F line=45
-f side='RIGHT'
undefinedExample 2: Comprehensive Review
示例2:全面评审
bash
#!/bin/bash
OWNER="NeoLabHQ"
REPO="learning-platform-app"
PR=4bash
#!/bin/bash
OWNER="NeoLabHQ"
REPO="learning-platform-app"
PR=4Create review with multiple comments
创建包含多个评论的评审
cat <<EOF | gh api repos/$OWNER/$REPO/pulls/$PR/reviews --input -
{
"event": "COMMENT",
"body": "Thanks for the PR! I've reviewed the changes and have a few suggestions.",
"comments": [
{
"path": "src/components/CourseCard.tsx",
"body": "Consider memoizing this component to prevent unnecessary re-renders",
"side": "RIGHT",
"line": 25
},
{
"path": "src/utils/courseProgress.ts",
"body": "This function could benefit from error handling for invalid course IDs",
"side": "RIGHT",
"line": 12
},
{
"path": "src/state/CourseProgressState.ts",
"body": "Consider adding JSDoc comments to document the expected behavior",
"side": "RIGHT",
"line": 8
}
]
}
EOF
undefinedcat <<EOF | gh api repos/$OWNER/$REPO/pulls/$PR/reviews --input -
{
"event": "COMMENT",
"body": "感谢提交PR!我已评审了变更,有一些建议。",
"comments": [
{
"path": "src/components/CourseCard.tsx",
"body": "考虑对该组件进行记忆化处理,以避免不必要的重渲染",
"side": "RIGHT",
"line": 25
},
{
"path": "src/utils/courseProgress.ts",
"body": "此函数可添加针对无效课程ID的错误处理",
"side": "RIGHT",
"line": 12
},
{
"path": "src/state/CourseProgressState.ts",
"body": "考虑添加JSDoc注释以记录预期行为",
"side": "RIGHT",
"line": 8
}
]
}
EOF
undefinedExample 3: Multi-line Comment
示例3:多行评论
bash
undefinedbash
undefinedComment on a range of lines (e.g., lines 10-15)
对一系列行进行评论(例如,第10-15行)
gh api repos/$OWNER/$REPO/pulls/$PR/comments
-f body='This entire block could be simplified using array destructuring'
-f commit_id="$COMMIT"
-f path='src/utils/parser.ts'
-F start_line=10
-f start_side='RIGHT'
-F line=15
-f side='RIGHT'
-f body='This entire block could be simplified using array destructuring'
-f commit_id="$COMMIT"
-f path='src/utils/parser.ts'
-F start_line=10
-f start_side='RIGHT'
-F line=15
-f side='RIGHT'
undefinedgh api repos/$OWNER/$REPO/pulls/$PR/comments
-f body='整个代码块可使用数组解构简化'
-f commit_id="$COMMIT"
-f path='src/utils/parser.ts'
-F start_line=10
-f start_side='RIGHT'
-F line=15
-f side='RIGHT'
-f body='整个代码块可使用数组解构简化'
-f commit_id="$COMMIT"
-f path='src/utils/parser.ts'
-F start_line=10
-f start_side='RIGHT'
-F line=15
-f side='RIGHT'
undefinedHelpful Helper Scripts
实用辅助脚本
Get PR Files and Lines
获取PR文件和行信息
bash
#!/bin/bashbash
#!/bin/bashpr-files.sh - List all files changed in a PR with line counts
pr-files.sh - 列出PR中所有变更的文件及行数统计
OWNER="$1"
REPO="$2"
PR="$3"
gh api repos/$OWNER/$REPO/pulls/$PR/files --jq '.[] | "(.filename): +(.additions)/-(.deletions)"'
undefinedOWNER="$1"
REPO="$2"
PR="$3"
gh api repos/$OWNER/$REPO/pulls/$PR/files --jq '.[] | "(.filename): +(.additions)/-(.deletions)"'
undefinedCheck Review Status
检查评审状态
bash
#!/bin/bashbash
#!/bin/bashcheck-reviews.sh - Check review status for a PR
check-reviews.sh - 检查PR的评审状态
OWNER="$1"
REPO="$2"
PR="$3"
echo "=== Reviews ==="
gh api repos/$OWNER/$REPO/pulls/$PR/reviews --jq '.[] | "(.user.login): (.state) at (.submitted_at)"'
echo -e "\n=== Pending Reviews ==="
gh api repos/$OWNER/$REPO/pulls/$PR/reviews --jq '.[] | select(.state=="PENDING") | "(.user.login): (.state)"'
undefinedOWNER="$1"
REPO="$2"
PR="$3"
echo "=== 评审列表 ==="
gh api repos/$OWNER/$REPO/pulls/$PR/reviews --jq '.[] | "(.user.login): (.state) at (.submitted_at)"'
echo -e "\n=== 待处理评审 ==="
gh api repos/$OWNER/$REPO/pulls/$PR/reviews --jq '.[] | select(.state=="PENDING") | "(.user.login): (.state)"'
undefinedRelated Documentation
相关文档
- GitHub API: Pull Request Review Comments
- GitHub API: Pull Request Reviews
- GitHub CLI Manual
- Create PR Command
- Commit Command
- GitHub API: 拉取请求评审评论
- GitHub API: 拉取请求评审
- GitHub CLI手册
- 创建PR命令
- 提交命令
API Reference
API参考
POST /repos/{owner}/{repo}/pulls/{pull_number}/comments
POST /repos/{owner}/{repo}/pulls/{pull_number}/comments
Creates a review comment on a specific line.
Endpoint:
https://api.github.com/repos/{owner}/{repo}/pulls/{pull_number}/commentsParameters:
- (string, required): Comment text
body - (string, required): SHA of commit
commit_id - (string, required): Relative file path
path - (integer, required): Line number in diff
line - (string, required): "LEFT" or "RIGHT"
side - (integer, optional): Start line for multi-line
start_line - (string, optional): Start side for multi-line
start_side
在特定行创建评审评论。
端点:
https://api.github.com/repos/{owner}/{repo}/pulls/{pull_number}/comments参数:
- (string,必填):评论文本
body - (string,必填):提交的SHA值
commit_id - (string,必填):文件相对路径
path - (integer,必填):差异中的行号
line - (string,必填):"LEFT"或"RIGHT"
side - (integer,可选):多行评论的起始行
start_line - (string,可选):多行评论的起始侧
start_side
POST /repos/{owner}/{repo}/pulls/{pull_number}/reviews
POST /repos/{owner}/{repo}/pulls/{pull_number}/reviews
Creates a review with optional line-specific comments.
Endpoint:
https://api.github.com/repos/{owner}/{repo}/pulls/{pull_number}/reviewsParameters:
- (string, required): "APPROVE", "REQUEST_CHANGES", or "COMMENT"
event - (string, optional): Overall review comment
body - (array, optional): Array of comment objects
comments - (string, optional): SHA of commit to review
commit_id
Comment Object:
- (string, required): Relative file path
path - (string, required): Comment text
body - (integer, required): Line number in diff
line - (string, required): "LEFT" or "RIGHT"
side - (integer, optional): Start line for multi-line
start_line - (string, optional): Start side for multi-line
start_side
创建包含可选特定行评论的评审。
端点:
https://api.github.com/repos/{owner}/{repo}/pulls/{pull_number}/reviews参数:
- (string,必填):"APPROVE"、"REQUEST_CHANGES"或"COMMENT"
event - (string,可选):整体评审评论
body - (array,可选):评论对象数组
comments - (string,可选):要评审的提交SHA值
commit_id
评论对象:
- (string,必填):文件相对路径
path - (string,必填):评论文本
body - (integer,必填):差异中的行号
line - (string,必填):"LEFT"或"RIGHT"
side - (integer,可选):多行评论的起始行
start_line - (string,可选):多行评论的起始侧
start_side