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
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A Node.js wrapper for GitHub API.
Install via npm
m install github
or
Install via git clone
t clone https://github.com/mikedeboer/node-github.git
node-github
m install
Client API: https://mikedeboer.github.io/node-github/
GitHub API: https://developer.github.com/v3/
Create test auth file for running tests/examples.
testAuth.json
"token": "<TOKEN>"
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));
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.
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!");
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:
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
}
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
.
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/
Run all tests
m test
Or run a specific test
m test test/issuesTest.js
MIT license. See the LICENSE file for details.