# github-diff-tool

> A TypeScript package for getting GitHub diffs with color formatting

Latest version **1.0.6** (published 2024-10-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install github-diff-tool
pnpm add github-diff-tool
yarn add github-diff-tool
bun add github-diff-tool
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2024-10-27 |
| First published | 2024-10-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 71 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | sshivaditya |
| Keywords | github, diff, git, octokit |

## Links

- npm: https://www.npmjs.com/package/github-diff-tool
- npm.io page: https://npm.io/package/github-diff-tool

## Dependencies (3)

- [dotenv](https://npm.io/package/dotenv.md) ^16.3.1
- [esbuild](https://npm.io/package/esbuild.md) ^0.24.0
- [octokit](https://npm.io/package/octokit.md) ^4.0.2

## Recent versions

- 1.0.6 (latest) — 2024-10-27
- 1.0.5 — 2024-10-27
- 1.0.4 — 2024-10-27
- 1.0.3 — 2024-10-27
- 1.0.2 — 2024-10-27
- 1.0.1 — 2024-10-27
- 1.0.0 — 2024-10-27

## README

# GithubDiff

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

## Installation

```bash
npm install githubdiff
```

## Usage

```typescript
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

```typescript
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

```typescript
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

---
_Source: https://npm.io/package/github-diff-tool · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
