kadirahq/node-github

Name: node-github

Owner: KADIRA

Description: node library to access the GitHub API

Forked from: octokit/rest.js

Created: 2016-06-29 04:54:57.0

Updated: 2016-06-29 04:54:57.0

Pushed: 2016-06-29 07:57:18.0

Homepage: http://mikedeboer.github.com/node-github/

Size: 1872

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Node-github

A Node.js wrapper for GitHub API.

Installation

Install via npm NPM version

m install github

or

Install via git clone

t clone https://github.com/mikedeboer/node-github.git
 node-github
m install
Documentation

Client API: https://mikedeboer.github.io/node-github/
GitHub API: https://developer.github.com/v3/

Test auth file

Create test auth file for running tests/examples.

testAuth.json

"token": "<TOKEN>"

Example

Get all followers for user “defunkt”:

GitHubApi = require("github");

github = new GitHubApi({
// optional
debug: true,
protocol: "https",
host: "github.my-GHE-enabled-company.com", // should be api.github.com for GitHub
pathPrefix: "/api/v3", // for some GHEs; none for GitHub
headers: {
    "user-agent": "My-Cool-GitHub-App" // GitHub is happy with a unique user agent
},
Promise: require('bluebird'),
followRedirects: false, // default: true; there's currently an issue with non-get redirects, so allow ability to disable follow-redirects
timeout: 5000

ub.users.getFollowingForUser({
// optional:
// headers: {
//     "cookie": "blahblah"
// },
user: "defunkt"
unction(err, res) {
console.log(JSON.stringify(res));

Pagination

There are a few pagination-related methods:

extPage(link)
reviousPage(link)
irstPage(link)
astPage(link)

extPage(link, headers, callback)
reviousPage(link, headers, callback)
irstPage(link, headers, callback)
astPage(link, headers, callback)

: link is the response object or the contents of the Link header

See here and here for examples.

Authentication

Most GitHub API calls don't require authentication. As a rule of thumb: If you can see the information by visiting the site without being logged in, you don't have to be authenticated to retrieve the same information through the API. Of course calls, which change data or read sensitive information have to be authenticated.

You need the GitHub user name and the API key for authentication. The API key can be found in the user's Account Settings.

asic
ub.authenticate({
type: "basic",
username: USERNAME,
password: PASSWORD


Auth2
ub.authenticate({
type: "oauth",
token: AUTH_TOKEN


Auth2 Key/Secret (to get a token)
ub.authenticate({
type: "oauth",
key: CLIENT_ID,
secret: CLIENT_SECRET

Note: authenticate is synchronous because it only stores the credentials for the next request.

Once authenticated you can update a user field like so:

ub.users.update({
location: "Argentina"
unction(err) {
console.log("done!");

Creating tokens for your application

Create a new authorization for your application giving it access to the wanted scopes you need instead of relying on username / password and is the way to go if you have two-factor authentication on.

For example:

  1. Use github.authenticate() to auth with GitHub using your username / password
  2. Create an application token programmatically with the scopes you need and, if you use two-factor authentication send the X-GitHub-OTP header with the one-time-password you get on your token device.
ub.authorization.create({
scopes: ["user", "public_repo", "repo", "repo:status", "gist"],
note: "what this auth is for",
note_url: "http://url-to-this-auth-app",
headers: {
    "X-GitHub-OTP": "two-factor-code"
}
unction(err, res) {
if (res.token) {
    //save and use res.token as in the Oauth process above from now on
}

Preview

Some endpoints are in a preview period and require a custom Accept header. See examples/getReactionsForIssue.js for an example. For updates on endpoints under preview, see https://developer.github.com/changes/.

Relatedly, the Migrations api requires an Accept header value of application/vnd.github.wyandotte-preview+json.

Update docs/tests

When updating routes.json, you'll want to update/generate docs/tests:

de lib/generate.js

Dev note for updating apidoc for github pages:

m install apidoc -g
idoc -i doc/ -o apidoc/
Tests

Run all tests

m test

Or run a specific test

m test test/issuesTest.js
LICENSE

MIT license. See the LICENSE file for details.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.