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 🙏

© 2024 – Pkg Stats / Ryan Hefner

github-diff-tool

v1.0.6

Published

A TypeScript package for getting GitHub diffs with color formatting

Downloads

1,150

Readme

GithubDiff

A TypeScript package that provides easy access to GitHub diff functionality with colored output support.

Installation

npm install githubdiff

Usage

import { Octokit } from 'octokit';
import { GithubDiff } from 'githubdiff';

// Initialize Octokit with your GitHub token
const octokit = new Octokit({ auth: 'your-github-token' });

// Create an instance of GithubDiff
const githubDiff = new GithubDiff(octokit);

// Get all diffs from a pull request with filenames
const allDiffs = await githubDiff.getPullRequestDiffs(
    'owner-name',
    'repo-name',
    123 // PR number
);
console.log(allDiffs); // Shows all diffs with filenames in color

// Get a summary of changes in a pull request
const summary = await githubDiff.getPullRequestSummary(
    'owner-name',
    'repo-name',
    123 // PR number
);
console.log(summary); // Shows a list of changed files with their status

// Get colored diff between specific commits
const diffResult = await githubDiff.getColoredDiff({
    owner: 'owner-name',
    repo: 'repo-name',
    startCommitSha: 'older-commit-sha', // Base (older) commit
    endCommitSha: 'newer-commit-sha',   // Head (newer) commit
    filePath: 'path/to/file'
});

// Get diff for a specific file in a PR
const prDiff = await githubDiff.getPullRequestDiff({
    owner: 'owner-name',
    repo: 'repo-name',
    pullNumber: 123,
    filePath: 'path/to/file'
});

Features

  • Get all diffs from a pull request with filenames and colored output
  • Get a summary of all changed files in a pull request
  • Get diffs between any two commits using SHA hashes
  • Get diffs for specific files in pull requests
  • Colored output support:
    • Green for additions
    • Red for deletions
    • Cyan for filenames
  • Plain text diff output option
  • TypeScript support with full type definitions
  • Detailed error messages

API

GithubDiff

Constructor

constructor(octokit: Octokit)

Creates a new instance of GithubDiff with the provided Octokit instance.

Methods

getPullRequestDiffs(owner: string, repo: string, pullNumber: number): Promise<string>

Get all diffs from a pull request with filenames. Returns a formatted string with all changes.

getPullRequestSummary(owner: string, repo: string, pullNumber: number): Promise<string>

Get a summary of all changed files in a pull request. Returns a list of files with their status.

getColoredDiff(options: DiffOptions): Promise<string>

Get a colored diff between two commits for a specific file.

getPlainDiff(options: DiffOptions): Promise<string>

Get a plain text diff between two commits for a specific file.

getPullRequestDiff(options: PullRequestDiffOptions): Promise<string>

Get a colored diff for a specific file in a pull request.

Interfaces

interface DiffOptions {
    owner: string;          // Repository owner
    repo: string;           // Repository name
    startCommitSha: string; // Base (older) commit SHA hash
    endCommitSha: string;   // Head (newer) commit SHA hash
    filePath: string;       // Path to the file
}

interface PullRequestDiffOptions {
    owner: string;      // Repository owner
    repo: string;       // Repository name
    pullNumber: number; // Pull request number
    filePath: string;   // Path to the file
}

Important Notes

  • When comparing commits, the order matters:
    • startCommitSha should be the older (base) commit
    • endCommitSha should be the newer (head) commit
  • The package provides detailed error messages if files are not found
  • All diffs are color-coded for better readability
  • Filenames are highlighted in cyan in the stacked diff output

License

ISC