attach-review-to-pr

Add line-specific review comments to pull requests using GitHub CLI API

By neolabhq · 1,055 installs

npx skills add neolabhq/context-engineering-kit --skill attach-review-to-pr

Source repository · Upstream listing

How 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 ( gh ) API or mcp github inline comment create inline comment if it not available, similar to how the GitHub UI allows commenting on specific lines of code. Preferred Approach: Using MCP GitHub Tools If available , use the mcp github inline comment create inline comment 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. Fallback : If the MCP tool is not available, use the GitHub CLI ( gh ) API methods described below: For single comments: Use the /comments endpoint (see [Adding a Single Line Specific Comment]( adding a single line specific comment)) For multiple comments: Use the /reviews endpoint (see [Adding Multiple Line Specific Comments Together]( adding multiple line specific comments together)) Overview While gh pr review 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 gh api command to call GitHub's REST API directly. Prerequisites 1. GitHub CLI installed and authenticated: 2. Access to the repository and pull request you want to review Understanding GitHub's Review Comment System GitHub has two types of PR comments: 1. Issue Comments General comments on the PR conversation 2. Review Comments Line specific comments on code changes Review comments can be added in two ways: Single comment Using the /pulls/{pr}/comments endpoint Review with multiple comments Using the /pulls/{pr}/reviews endpoint Adding a Single Line Specific Comment Basic Syntax Parameters Explained Parameter Type Required Description body string Yes The text of the review comment (supports Markdown) commit id string Yes The SHA of the commit to comment on path string Yes Relative path to the file being commented on line integer Yes The line number in the diff (use F for integers) side string Yes RIGHT for new/modified lines, LEFT for deleted lines start line integer No For multi line comments, the starting line start side string No For multi line comments, the starting side Parameter Flags f ( field) For string values F ( field) For integer values (note the capital F) Complete Example Understanding Line Numbers The line parameter refers to the position in the diff , not the absolute line number in the file: 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 start line and line to specify the range Response On success, returns a JSON object with comment details: Adding Multiple Line Specific Comments Together To add multiple comments across different files in a single review, use the /reviews endpoint with JSON input. Why 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" Basic Syntax Review Event Types Event Description When to Use COMMENT General review comment Just leaving feedback without approval APPROVE Approve the PR Changes look good, ready to merge REQUEST CHANGES Request changes Issues that must be fixed before merge Complete Example Response Common Issues and Solutions Issue 1: "user id can only have one pending review per pull request" Error Message: 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 Solution 2: Use the single comment endpoint instead Issue 2: Array syntax not working with raw field Failed Attempt: Error: Solution: Use JSON input via heredoc: Issue 3: Invalid line number Error Message: Cause: 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 commit id (the latest commit in the PR) Issue 4: Wrong commit id Error Message: Solution: Get the latest commit SHA: Best Practices 1. Get PR Information First Before adding comments, gather necessary information: 2. Check for Pending Reviews 3. Use Meaningful Comment Text Be specific and constructive Reference documentation or best practices Suggest alternatives when requesting changes Use code blocks for code suggestions: 4. Batch Related Comments 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 Workflow Examples Example 1: Quick Single Comment Example 2: Comprehensive Review Example 3: Multi line Comment Helpful Helper Scripts Get PR Files and Lines Check Review Status Related Documentation [GitHub API: Pull Request Review Comments](https://docs.github.com/rest/pulls/comments) [GitHub API: Pull Request Reviews](https://docs.github.com/rest/pulls/reviews) [GitHub CLI Manual](https://cli.github.com/manual/) [Create PR Command](./create pr.md) [Commit Command](./commit.md) API Reference 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}/comments Parameters: body (string, required): Comment text commit id (string, required): SHA of commit path (string, required): Relative file path line (integer, required): Line number in diff side (string, required): "LEFT" or "RIGHT" start line (integer, optional): Start line for multi line start side (string, optional): Start side for multi line 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}/reviews Parameters: event (string, required): "APPROVE", "REQUEST CHANGES", or "COMMENT" body (string, optional): Overall review comment comments (array, optional): Array of comment objects commit id (string, optional): SHA of commit to review Comment Object: path (string, required): Relative file path body (string, required): Comment text line (integer, required): Line number in diff side (string, required): "LEFT" or "RIGHT" start line (integer, optional): Start line for multi line start side (string, optional): Start side for multi line