npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

gh-diff-extractor

v1.0.0

Published

A CLI tool to extract git diffs from GitHub pull request files pages, supporting private repositories

Readme

gh-diff-extractor

A CLI tool to extract git diffs from GitHub pull request files pages, supporting private repositories.

Features

  • 🔗 Extract diffs from GitHub PR URLs (including /files pages)
  • 🔐 Support for private repositories with authentication
  • 📄 Multiple output formats (diff and patch)
  • 🎨 Colorised terminal output
  • 📊 Diff statistics
  • 💾 Save to file or output to stdout
  • ⚙️ Flexible authentication (environment variables, config file, or CLI option)

Installation

Global Installation

npm install -g gh-diff-extractor

Local Installation

npm install gh-diff-extractor

Authentication

To access private repositories, you need a GitHub Personal Access Token. The tool supports multiple ways to provide authentication:

1. Environment Variable (Recommended)

export GITHUB_TOKEN=your_github_token_here

2. Configuration File

gh-diff-extractor config --token your_github_token_here

3. Command Line Option

gh-diff-extractor --token your_github_token_here <url>

Creating a GitHub Token

  1. Go to GitHub Settings > Developer settings > Personal access tokens
  2. Click "Generate new token"
  3. Select the following scopes:
    • repo (for private repositories)
    • public_repo (for public repositories)
  4. Copy the generated token

Usage

Basic Usage

# Extract diff from a public PR
gh-diff-extractor https://github.com/owner/repo/pull/123

# Extract diff from a private PR (requires authentication)
gh-diff-extractor https://github.com/owner/repo/pull/123/files

# Get patch format instead of diff
gh-diff-extractor --patch https://github.com/owner/repo/pull/123

# Save to file
gh-diff-extractor --output pr-123.diff https://github.com/owner/repo/pull/123

# Show statistics
gh-diff-extractor --stats https://github.com/owner/repo/pull/123

# Disable colours
gh-diff-extractor --no-color https://github.com/owner/repo/pull/123

Supported URL Formats

The tool accepts various GitHub PR URL formats:

  • https://github.com/owner/repo/pull/123
  • https://github.com/owner/repo/pull/123/files
  • https://github.com/owner/repo/pull/123/commits
  • github.com/owner/repo/pull/123 (protocol will be added automatically)

Command Options

Usage: gh-diff-extractor [options] <url>

Arguments:
  url                          GitHub pull request URL

Options:
  -V, --version               output the version number
  -t, --token <token>         GitHub personal access token
  -o, --output <file>         Output file path (if not specified, prints to stdout)
  -p, --patch                 Get patch format instead of diff format
  -v, --verbose               Show verbose output
  --no-color                  Disable coloured output
  --stats                     Show diff statistics
  -h, --help                  display help for command

Configuration Commands

# Set GitHub token
gh-diff-extractor config --token your_github_token_here

# Validate token
gh-diff-extractor validate

# Validate specific token
gh-diff-extractor validate --token your_github_token_here

Examples

Extract diff with statistics

gh-diff-extractor --stats https://github.com/facebook/react/pull/25123

Output:

Files changed: 3, Insertions: 45, Deletions: 12
diff --git a/packages/react/src/React.js b/packages/react/src/React.js
index 1234567..abcdefg 100644
--- a/packages/react/src/React.js
+++ b/packages/react/src/React.js
...

Save diff to file

gh-diff-extractor --output react-pr-25123.diff https://github.com/facebook/react/pull/25123

Get patch format

gh-diff-extractor --patch https://github.com/facebook/react/pull/25123

Error Handling

The tool provides clear error messages for common issues:

  • Invalid URL: Clear message about expected URL format
  • Authentication failure: Instructions on how to set up authentication
  • Repository not found: Verification steps for repository access
  • Network issues: Guidance on connectivity problems

Development

Setup

git clone https://github.com/Sharma-IT/gh-diff-extractor.git
cd gh-diff-extractor
npm install

Running Tests

npm test
npm run test:coverage

Building

npm run build

Development Mode

npm run dev -- https://github.com/owner/repo/pull/123

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

Support

If you encounter any issues or have questions:

  1. Check the Issues page
  2. Create a new issue with detailed information about the problem
  3. Include the command you ran and the error message

Changelog

v1.0.0

  • Initial release
  • Support for GitHub PR diff extraction
  • Authentication via tokens
  • Multiple output formats
  • Colorised terminal output
  • Comprehensive error handling