github-diff

1.3.3 • Public • Published

github-diff

Get a diff between 2 commits or tags of a github project

Usage

Setup

In order to use github-diff to access a private repository you'll need to create a personal access token and set the environment variable GITHUB_DIFF_TOKEN to the token

You can run the following in the command line or add it your .bashrc

export GITHUB_DIFF_TOKEN=token

Arguments and return values

github-diff takes the following arguments

  • repository: a github repository name and owner split by a /: ex alex-e-leon/github-diff
  • base: a commit hash or tag to diff from
  • head: a commit hash or tag to diff to

github-diff returns a promise that returns the following structure:

[{ filename, patch, header, status, fileA, fileB}, ...]
  • filename: The full path of the file from the base of the repo, ex: /src/my-file.js
  • patch: The patch provided by github for the file. Looks like a regular git formatted patch without the header
  • header: A basic git patch style header. Currently doesn't include commit hashes, but should validate if used with git apply
  • status: The diff status for the file. Returns one of modified, renamed, deleted, added, etc. See git docs for all options
  • fileA: The contents of the base file (if it exists in base)
  • fileB: The contents of the head file (if it exists in head)
  • previousFilename: The previous filename (if the file has been renamed)

Node example

import githubDiff from 'github-diff';
githubDiff('alex-e-leon/github-diff', 'v1.0.0', 'v.1.0.1').then((patches) => {
  console.log(patches);
});

Cli example

node cli.js domain-group/fe-boilerplate-generator v2.3.0 v3.0.0

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.3.3
    268
    • latest

Version History

Package Sidebar

Install

npm i github-diff

Weekly Downloads

271

Version

1.3.3

License

ISC

Unpacked Size

7.23 kB

Total Files

4

Last publish

Collaborators

  • alex-e-leon