---
name: github-pr-review-operation
description: Use this skill when the user needs to interact with a GitHub Pull Request — reviewing code, reading diffs, posting review comments, or replying to existing comments. Activate even when the user provides just a PR URL and asks to "check it" or "leave feedback" without explicitly mentioning "review."
title: github-pr-review-operation
canonical_url: https://skilld.dev/gh/shibayu36/agent-skills/github-pr-review-operation
last_updated: 2026-09-24T22:30:26.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install shibayu36/agent-skills/github-pr-review-operation`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/github-pr-review-operation`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/shibayu36/agent-skills/github-pr-review-operation) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/github-pr-review-operation`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/github-pr-review-operation --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/github-pr-review-operation --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# GitHub PR Review Operation

PR review operations using GitHub CLI (`gh`).

## Prerequisites

- `gh` installed
- Authenticated via `gh auth login`

## Resolving OWNER/REPO/NUMBER

**Never guess `OWNER`, `REPO`, or `NUMBER` from directory names, paths, or context.**
Incorrect guesses cause 404 errors and waste API calls.

Pick the approach that matches the input, then use the resulting `OWNER`, `REPO`, and
`NUMBER` in every Operation command that follows.

| Input | How to resolve |
|---|---|
| PR URL given (`https://github.com/OWNER/REPO/pull/NUMBER`) | Parse `OWNER`, `REPO`, `NUMBER` directly from the URL. |
| PR number given | Run `gh pr view <NUMBER> --json url --jq .url` and parse the returned URL. |
| No identifier (e.g., "this PR" on a branch) | Run `gh pr view --json url --jq .url` and parse the returned URL. |

For the `gh pr view` cases, the command resolves the number or branch against the current
working directory's git repository, so `OWNER/REPO` come from the real repo context
rather than a guess.

If `gh pr view` fails (not in a git repo, branch has no PR, invalid number), ask the user
for the full PR URL rather than guessing.

## Operations

### 1. Get PR Info

```bash
gh pr view NUMBER --repo OWNER/REPO --json title,body,author,state,baseRefName,headRefName,url
```

### 2. Get Diff (with line numbers)

```bash
gh pr diff NUMBER --repo OWNER/REPO | awk 'BEGIN {
  while ((getline line) > 0) {
    if (line ~ /^@@/) {
      match(line, /-[0-9]+/); old_line = substr(line, RSTART + 1, RLENGTH - 1)
      match(line, /\+[0-9]+/); new_line = substr(line, RSTART + 1, RLENGTH - 1)
      print line
    } else if (line ~ /^-/) { printf "L%-4d     | %s\n", old_line++, line }
    else if (line ~ /^\+/) { printf "     R%-4d| %s\n", new_line++, line }
    else if (line ~ /^ /) { printf "L%-4d R%-4d| %s\n", old_line++, new_line++, line }
    else print line
  }
}'
```

Example output:
```
@@ -46,15 +46,25 @@ jobs:
L46   R46  |            prompt: |
L49       | -            (deleted line)
     R49  | +            (added line)
L50   R50  |              # Review guidelines
```

- `L<number>`: LEFT (base) side line number - use with `side=LEFT` for inline comments
- `R<number>`: RIGHT (head) side line number - use with `side=RIGHT` for inline comments

### 3. Get Comments

Issue Comments (comments on the entire PR):
```bash
gh api repos/OWNER/REPO/issues/NUMBER/comments --jq '.[] | {id, user: .user.login, created_at, body}'
```

Review Comments (comments on specific code lines):
```bash
gh api repos/OWNER/REPO/pulls/NUMBER/comments --jq '.[] | {id, user: .user.login, path, line, created_at, body, in_reply_to_id}'
```

### 4. Comment on PR

```bash
gh pr comment NUMBER --repo OWNER/REPO --body "Comment body"
```

For a complex body (backticks, `$`, quotes, newlines), write the body to a file and pass it
with `--body-file <file>`:
```bash
gh pr comment NUMBER --repo OWNER/REPO --body-file <file>
```

### 5. Inline Comment (on specific code lines)

First, get the head commit SHA:
```bash
gh api repos/OWNER/REPO/pulls/NUMBER --jq '.head.sha'
```

Single line comment:
```bash
gh api repos/OWNER/REPO/pulls/NUMBER/comments \
  --method POST \
  -f body="Comment body" \
  -f commit_id="COMMIT_SHA" \
  -f path="src/example.py" \
  -F line=15 \
  -f side=RIGHT
```

Multi-line comment (lines 10-15):
```bash
gh api repos/OWNER/REPO/pulls/NUMBER/comments \
  --method POST \
  -f body="Comment body" \
  -f commit_id="COMMIT_SHA" \
  -f path="src/example.py" \
  -F line=15 \
  -f side=RIGHT \
  -F start_line=10 \
  -f start_side=RIGHT
```

For a complex body (backticks, `$`, quotes, newlines), write the body to a file and pass it
with `-F body=@<file>`. Do not use `-f body=@<file>` — `-f` (raw-field) does not expand `@`,
so the literal path is posted as the body.
```bash
gh api repos/OWNER/REPO/pulls/NUMBER/comments \
  --method POST \
  -F body=@<file> \
  -f commit_id="COMMIT_SHA" \
  -f path="src/example.py" \
  -F line=15 \
  -f side=RIGHT
```

**Notes:**
- `-f` (raw-field): sends the value as a literal string; does not expand `@file`
- `-F` (field): converts numbers/booleans by type and expands `@file` into file contents. Use `-F` for numeric parameters (`line`, `start_line`) and for passing a body from a file. Using `-f` for numeric parameters sends them as strings and causes errors
- `side`: `RIGHT` (added lines) or `LEFT` (deleted lines)

### 6. Reply to a Comment

```bash
gh api repos/OWNER/REPO/pulls/NUMBER/comments/COMMENT_ID/replies \
  --method POST \
  -f body="Reply body"
```

For a complex body, write it to a file and pass it with `-F body=@<file>` (see Operation 5).

Use the `id` obtained from comment retrieval as `COMMENT_ID`.
