pr-review-comments
作者: microsoft
用于向GitHub提交/发布内联PR审查评论的指南。当您需要在Pull Request的特定代码行上发布代码审查评论时使用此功能。
npx skills add https://github.com/microsoft/semantic-link-labs --skill pr-review-commentsPosting Inline PR Review Comments to GitHub
This skill documents how to post inline review comments to GitHub Pull Requests using the GitHub CLI (gh) and GitHub API. Inline comments appear directly on specific lines of code in the PR diff, making it easier for PR authors to identify and address issues.
When to Use This Skill
Use this skill when you need to:
- Post inline review comments on specific lines of a PR
- Automate code review feedback with targeted comments
- Submit batch review comments via the GitHub API
Prerequisites
-
GitHub CLI installed: Check with
gh --version- If not installed on Linux:
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null sudo apt update && sudo apt install gh -y
- If not installed on Linux:
-
GitHub CLI authenticated: Check with
gh auth status- If not authenticated:
gh auth login -h github.com -p https --web - Follow the device code flow to complete authentication
- If not authenticated:
Method: Using GitHub API with JSON Payload
Step 1: Get the PR's Head Commit SHA
COMMIT_SHA=$(gh api repos/{OWNER}/{REPO}/pulls/{PR_NUMBER} --jq '.head.sha')
echo "Commit SHA: $COMMIT_SHA"
Step 2: Create the Review JSON Payload
Create a JSON file with the review comments. Each comment needs:
path: The file path relative to repository rootline: The line number in the new version of the file (right side of diff)body: The comment content (supports Markdown)
cat > /tmp/review.json << 'EOF'
{
"commit_id": "YOUR_COMMIT_SHA_HERE",
"event": "COMMENT",
"comments": [
{
"path": "src/path/to/file.py",
"line": 40,
"body": "🔴 **Critical:** Description of the issue.\n\n**Suggested fix:**\n```python\n# your code here\n```"
},
{
"path": "src/path/to/another_file.py",
"line": 21,
"body": "🟡 **Minor:** Another issue description."
}
]
}
EOF
Step 3: Post the Review
gh api repos/{OWNER}/{REPO}/pulls/{PR_NUMBER}/reviews --method POST --input /tmp/review.json
Important Notes
Line Numbers
- The
linefield refers to the line number in the new version of the file (right side of the diff) - For deleted lines, use
side: "LEFT"and the line number from the old version - Make sure the line number exists in the diff, otherwise the API will reject the comment
Event Types
| Event | Description |
|---|---|
"COMMENT" | Just add comments without approving/requesting changes |
"APPROVE" | Approve the PR with comments |
"REQUEST_CHANGES" | Request changes with comments |
Comment Body Formatting
- Supports full GitHub Markdown
- Use
\nfor newlines in JSON - Escape special characters properly
- Use emoji prefixes for severity: 🔴 Critical/High, 🟡 Medium/Minor, 🟢 Suggestion
Multi-line Comments
For commenting on a range of lines:
{
"path": "src/file.py",
"start_line": 10,
"line": 15,
"body": "This comment spans lines 10-15"
}
Troubleshooting
| Issue | Solution |
|---|---|
| "Validation Failed" error | Check that the line number exists in the PR diff; verify the file path is correct |
| "Resource not accessible" error | Ensure you have write access to the repository; re-authenticate with gh auth login |
| Comments not appearing on specific lines | The line must be part of the diff (added, modified, or within context lines) |
Alternative: Using gh pr review Command
For simpler reviews without inline comments:
gh pr review {PR_NUMBER} --repo {OWNER}/{REPO} --comment --body "Your review comment here"
This posts a general review comment but does not support inline comments on specific lines.
Repository-Specific Information
- Repository:
microsoft/semantic-link-labs - Common file paths:
src/sempy_labs/{module}/_items.pysrc/sempy_labs/{module}/__init__.py
- Review comment conventions:
- Use severity emojis: 🔴 Critical, 🟡 Medium, 🟢 Minor
- Include "Suggested fix" with code blocks
- Reference specific line numbers
Examples
See the examples/ folder for complete working scripts:
- post_pr1059_review.sh - Example script posting inline review comments to PR #1059
来自 microsoft 的更多技能
oss-growth
microsoft
OSS增长黑客角色
official
microsoft-foundry
microsoft
端到端部署、评估和管理Foundry代理:Docker构建、ACR推送、托管/提示代理创建、容器启动、批量评估、持续评估、提示优化工作流、agent.yaml、从追踪中整理数据集。用途:将代理部署到Foundry、托管代理、创建代理、调用代理、评估代理、运行批量评估、持续评估、持续监控、持续评估状态、优化提示、改进提示、提示优化器、优化代理指令、改进代理...
officialdevelopmentdevops
azure-ai
microsoft
用于Azure AI:搜索、语音、OpenAI、文档智能。支持搜索、向量/混合搜索、语音转文字、文字转语音、转录、OCR。适用场景:AI搜索、查询搜索、向量搜索、混合搜索、语义搜索、语音转文字、文字转语音、转录、OCR、文字转语音。
officialdevelopmentapi
azure-deploy
microsoft
对已准备好的应用程序执行Azure部署,这些程序需包含现有的.azure/deployment-plan.md和基础设施文件。当用户要求创建新应用程序时,请勿使用此技能——应改用azure-prepare。此技能运行azd up、azd deploy、terraform apply和az deployment命令,并内置错误恢复机制。需要来自azure-prepare的.azure/deployment-plan.md以及来自azure-validate的已验证状态。适用场景:"运行azd up"、"运行azd deploy"、"执行部署"...
officialdevopsaws
azure-storage
microsoft
Azure存储服务,包括Blob存储、文件共享、队列存储、表存储和Data Lake。解答关于存储访问层(热、冷、冷、归档)的问题,说明各层的使用场景及对比。提供对象存储、SMB文件共享、异步消息传递、NoSQL键值存储和大数据分析。包含生命周期管理。用途:Blob存储、文件共享、队列存储、表存储、Data Lake、上传文件、下载Blob、存储账户、访问层等。
officialdevelopmentdatabase
azure-diagnostics
microsoft
使用AppLens、Azure Monitor、资源健康和安全分类调试Azure生产问题。适用场景:调试生产问题、排查应用服务、应用服务CPU过高、应用服务部署失败、排查容器应用、排查函数、排查AKS、kubectl无法连接、kube-system/CoreDNS故障、Pod挂起、CrashLoop、节点未就绪、升级失败、分析日志、KQL、洞察、镜像拉取失败、冷启动问题、健康探测失败……
officialdevopsdevelopment
azure-prepare
microsoft
为Azure应用准备部署(基础设施Bicep/Terraform、azure.yaml、Dockerfile)。用于创建/现代化或创建+部署;不用于跨云迁移(使用azure-cloud-migrate)。请勿用于:copilot-sdk应用(使用azure-hosted-copilot-sdk)。适用场景:"创建应用"、"构建Web应用"、"创建API"、"创建无服务器HTTP API"、"创建前端"、"创建后端"、"构建服务"、"现代化应用"、"更新应用"、"添加身份验证"、"添加缓存"、"托管在Azure上"、"创建并...
officialdevelopmentdevops
azure-validate
microsoft
部署前对Azure就绪状态进行验证。对配置、基础设施(Bicep或Terraform)、RBAC角色分配、托管标识权限及先决条件进行深度检查,然后再部署。适用场景:验证我的应用、检查部署就绪状态、运行预检、验证配置、检查是否可部署、验证azure.yaml、验证Bicep、部署前测试、排查部署错误、验证Azure Functions、验证函数应用、验证无服务器...
officialdevopstesting