1.0.6 • Published 6 months ago

github-diff-tool v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

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

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago