Pull request diff fetcher

From shopsys/shopsys · View interactive version

Pull request diff fetcher is an AI agent skill from the GitHub repository shopsys/shopsys. Fetches pull request data including diff, metadata, and commits

How to use this skill

Skill file

PR Diff Fetcher

This helper is responsible for fetching pull request data including diff, metadata, and commits.

Input

You will receive ONE of:

Your Task

Fetch complete PR data using the best available method and return structured information.

Method Priority: gh CLI → WebFetch → Local Git

Method 1: GitHub CLI (gh) - PREFERRED

Step 1: Check gh availability

  1. Check installation: gh --version
  1. Check authentication: gh auth status

Step 2: Fetch PR data using gh

  1. Extract PR metadata and BASE branch (later steps diff against it):

```bash

gh pr view {PR_NUMBER} --json baseRefName,title,body,labels

```

  1. Get complete diff (PRIMARY DATA SOURCE):

```bash

gh pr diff {PR_NUMBER}

```

  1. Get commits (for movement detection):

```bash

gh pr view {PR_NUMBER} --json commits

```

Return to main command with:

Method 2: WebFetch with GitHub API (fallback if gh not available)

Step 1: Extract PR metadata using GitHub REST API

WebFetch: https://api.github.com/repos/shopsys/shopsys/pulls/{PR_NUMBER}
Prompt: "Extract from this JSON: base.ref (base branch name), title, body (description), labels[].name (label names), head.ref (head branch name)"

Store the BASE branch (base.ref) - you'll need it if diff is large.

Step 2: Get complete diff

WebFetch: https://patch-diff.githubusercontent.com/raw/shopsys/shopsys/pull/{PR_NUMBER}.diff
Prompt: "Return the complete diff content exactly as-is"

Step 3: Get commits using GitHub REST API

WebFetch: https://api.github.com/repos/shopsys/shopsys/pulls/{PR_NUMBER}/commits
Prompt: "Extract commit messages from the JSON array (commit.message field for each item), looking for keywords: 'move', 'moved', 'moving' combined with 'from project-base' or 'to package'"

Step 4: Decide if local git needed

If local git needed, ask main command to confirm with user: "The diff is large. I'll use local git for analysis. Current branch is {branch}. Is the base branch '{extracted_base_branch}'?"

Then use: git diff {base_branch}...HEAD

Return to main command with:

Method 3: Local Git (when no PR provided)

When input is "current-branch":

  1. Get current branch:

```bash

git branch --show-current

```

  1. Resolve the base branch: gh repo view --json defaultBranchRef -q .defaultBranchRef.name (fallback git symbolic-ref refs/remotes/origin/HEAD), then git fetch origin <base> and use origin/<base> as {base_branch}.
  1. Collect the history and diff:

```bash

git log {base_branch}...HEAD --oneline

git diff {base_branch}...HEAD

```

Return to main command with:

Error Handling

If any method fails:

Output Format

Always return a structured summary in this format:

## PR Data Fetch Results

**Method used:** {gh|webfetch|webfetch+git|local-git}
**PR Number:** {number or "N/A"}
**Base Branch:** {branch name}
**PR Title:** {title}

**Diff size:** {approximate size or "complete"}
**Commits analyzed:** {count}
**Movement indicators found:** {yes/no + details}

**Status:** ✅ Success | ❌ Failed

### Metadata
{JSON structure with all extracted data}

### Diff Content
{First 100 lines of diff as preview}
[Full diff saved to <scratchpad path> — pass this path to the caller]

### Commit Messages
{List of commit messages with movement indicators highlighted}

Important Notes

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.