Back to Skills

retrieve-diff-from-github-pr

verified

Retrieve code diff from a GitHub Pull Request via GitHub API. Use this as the first step in a code review pipeline when reviewing GitHub PRs.

View on GitHub

Marketplace

codereview-skills

xinbenlv/codereview-skills

Plugin

codereview

Repository

xinbenlv/codereview-skills

skills/retrieve-diff-from-github-pr/SKILL.md

Last Verified

January 20, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/xinbenlv/codereview-skills/blob/main/skills/retrieve-diff-from-github-pr/SKILL.md -a claude-code --skill retrieve-diff-from-github-pr

Installation paths:

Claude
.claude/skills/retrieve-diff-from-github-pr/
Powered by add-skill CLI

Instructions

# Retrieve Diff from GitHub PR Skill

An **input skill** that retrieves code diff and PR metadata from GitHub via the API. This is the entry point for reviewing GitHub Pull Requests.

## Role

- **Fetch**: Get PR details and diff via GitHub API
- **Extract**: Parse changed files and their diffs
- **Context**: Gather PR metadata (title, description, author, reviews)

## Inputs

| Input | Required | Description |
|-------|----------|-------------|
| `owner` | Yes | Repository owner (username or organization) |
| `repo` | Yes | Repository name |
| `pull_number` | Yes | Pull Request number |

## Outputs

| Output | Description |
|--------|-------------|
| `pr_info` | PR metadata (title, description, author, state, labels) |
| `files` | List of changed files with patches |
| `commits` | List of commits in the PR |
| `base_ref` | Base branch reference |
| `head_ref` | Head branch reference |
| `diff` | Full unified diff content |

## Required MCP Tools

This skill uses the GitHub MCP server with the following tools:

| Tool | Purpose |
|------|---------|
| `get_pull_request` | Get PR details (title, body, state, author) |
| `get_pull_request_files` | Get list of changed files with patches |

## Step 1: Parse PR Reference

Accept PR reference in various formats:

| Format | Example | Parsing |
|--------|---------|---------|
| **Full URL** | `https://github.com/owner/repo/pull/123` | Extract owner, repo, pull_number |
| **Short reference** | `owner/repo#123` | Split on `/` and `#` |
| **Number only** | `123` | Requires owner/repo from context |

```
Regex for URL: github\.com/([^/]+)/([^/]+)/pull/(\d+)
Regex for short: ([^/]+)/([^#]+)#(\d+)
```

## Step 2: Fetch PR Details

Use the GitHub MCP tool to get PR information:

```json
{
  "tool": "get_pull_request",
  "server": "user-github",
  "arguments": {
    "owner": "<owner>",
    "repo": "<repo>",
    "pull_number": <number>
  }
}
```

This returns:
- PR title and description
- Author information
- Base and head branches
-

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
4966 chars