Loading...
Loading...
Add line-specific review comments to pull requests using GitHub CLI API
npx skill4agent add neolabhq/context-engineering-kit attach-review-to-prghmcp__github_inline_comment__create_inline_commentmcp__github_inline_comment__create_inline_commentgh/comments/reviewsgh pr reviewgh apigh auth status/pulls/{pr}/comments/pulls/{pr}/reviewsgh 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'| 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 |
-f-F# First, get the latest commit SHA for the PR
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'linestart_lineline{
"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"
}/reviewscat <<'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
}
]
}
EOF| 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 |
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
}
]
}
EOF{
"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"
}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"}]}# Check for pending reviews
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# Add 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'# This does NOT work - GitHub API receives an object, not an array
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'Invalid request. For 'properties/comments', {"0" => {...}, "1" => {...}} is not an array.cat <<'EOF' | gh api repos/{owner}/{repo}/pulls/{pr}/reviews --input -
{
"comments": [...]
}
EOFPull request review thread line must be part of the diffcommit_idcommit_sha is not part of the pull requestgh api repos/{owner}/{repo}/pulls/{pr_number} --jq '.head.sha'# Get PR details
gh pr view {pr_number} --json headRefOid,files
# Or use the API
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}'# Check if you have a pending review
gh api repos/{owner}/{repo}/pulls/{pr_number}/reviews \
--jq '.[] | select(.state=="PENDING" and .user.login=="YOUR_USERNAME")'Consider using async/await:
\`\`\`typescript
async function getData() {
const result = await fetch(url);
return result.json();
}
\`\`\`# For feedback during development
"event": "COMMENT"
# When approving
"event": "APPROVE"
# When blocking merge
"event": "REQUEST_CHANGES"#!/bin/bash
OWNER="NeoLabHQ"
REPO="learning-platform-app"
PR=4
# Get latest commit
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'#!/bin/bash
OWNER="NeoLabHQ"
REPO="learning-platform-app"
PR=4
# Create 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# Comment on a range of lines (e.g., lines 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'#!/bin/bash
# pr-files.sh - List all files changed in a PR with line counts
OWNER="$1"
REPO="$2"
PR="$3"
gh api repos/$OWNER/$REPO/pulls/$PR/files --jq '.[] | "\(.filename): +\(.additions)/-\(.deletions)"'#!/bin/bash
# check-reviews.sh - Check review status for a 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)"'https://api.github.com/repos/{owner}/{repo}/pulls/{pull_number}/commentsbodycommit_idpathlinesidestart_linestart_sidehttps://api.github.com/repos/{owner}/{repo}/pulls/{pull_number}/reviewseventbodycommentscommit_idpathbodylinesidestart_linestart_side