0.0.0 • Published 7 years ago

gh-compare-commits v0.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

gh-compare-commits

NPM version Build Status Coverage Status Dependency Status devDependency Status

A Node module to compare two commits on Github

const ghCompareCommits = require('gh-compare-commits');

ghCompareCommits('npm/npm', '2.x', 'master' result => {
  result.commits.map()
});
[
  {
    id: '3476797099',
    type: 'WatchEvent',
    actor: {
      id: 1131567,
      login: 'shinnn',
      gravatar_id: '',
      url: 'https://api.github.com/users/shinnn',
      avatar_url: 'https://avatars.githubusercontent.com/u/1131567?'
    },
    repo: {
      id: 32662888,
      name: 'purescript-contrib/node-purescript-bin',
      url: 'https://api.github.com/repos/purescript-contrib/node-purescript-bin'
    },
    payload: {
      action: 'started'
    },
    public: true,
    created_at: '2015-12-27T09:28:25Z',
    org: {
      id: 7391813,
      login: 'purescript-contrib',
      gravatar_id: '',
      url: 'https://api.github.com/orgs/purescript-contrib',
      avatar_url: 'https://avatars.githubusercontent.com/u/7391813?'
    }
  },
  // ...
]

Installation

Use npm.

npm install gh-compare-commits

API

const ghUserEvents = require('gh-compare-commits');

ghUserEvents(username , options)

username: String (a Github username, for example https://github.com/shinnn'shinnn')
options: Object (Request options and the additional ones)
Return: Promise instance

It creates API requests to get the list of events performed by the specific Github user.

When it gets the list successfully, the promise will be fulfilled with an array of event information objects.

When one of the request fails, the promise will be rejected with an error.

options.token

Type: String
Default: process.env.GITHUB_TOKEN

Use specific GitHub access token.

options.maxPageSize

Type: String (1 ... 10)
Default: 10

Set the number of pages to request per function call. One page includes up to 30 items. All items in the pages will be joined into one array when the promise is fulfilled.

Note that it creates multiple API requests if maxPageSize option is more than 1. In other words, one function call requires at least the same number of remaining rate limit as this option.

Race condition

Under race condition, for example a new event occurs while sending multiple paginated API requests, the result rarely includes some duplicated values. In this case gh-compare-commits omits the duplicates from the array. Therefore, the number of items sometimes doesn't correspond with 30 * options.maxPageSize.

options.publicOnly

Type: Boolean
Default: false

true restricts the events to only public ones even if you are authenticated as the given user.

options.verbose

Type: Boolean
Default: false

true adds an http.IncomingMessage object to the error message as response property.

ghUserEvents('shinnn', {token: 'invalid_token'}).then(err => {
  err.message; //=> 'Bad credentials'
  'response' in error; //=> false
});

ghUserEvents('shinnn', {
  token: 'invalid_token',
  verbose: true
}).then(err => {
  err.message; //=> 'Bad credentials'
  err.response; //=> {statusCode: 401, body: { ... }, headers: { ... }, ...}
});

License

Copyright (c) 2015 Shinnosuke Watanabe

Licensed under the MIT License.