Socket
Socket
Sign inDemoInstall

github-api

Package Overview
Dependencies
Maintainers
3
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github-api - npm Package Compare versions

Comparing version 0.10.4 to 0.10.6

.jshintrc

2

bower.json
{
"name": "github-api",
"main": "github.js",
"version": "0.10.3",
"version": "0.10.6",
"homepage": "https://github.com/michael/github",

@@ -6,0 +6,0 @@ "authors": [

@@ -14,3 +14,4 @@ /*!

(function() {
'use strict';
// Initial Setup

@@ -20,10 +21,16 @@ // -------------

var XMLHttpRequest, _;
/* istanbul ignore else */
if (typeof exports !== 'undefined') {
XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
_ = require('underscore');
btoa = require('btoa');
} else {
_ = window._;
if (typeof btoa === 'undefined') {
var btoa = require('btoa'); //jshint ignore:line
}
} else {
_ = window._;
}
//prefer native XMLHttpRequest always
/* istanbul ignore if */
if (typeof window !== 'undefined' && typeof window.XMLHttpRequest !== 'undefined'){

@@ -34,5 +41,5 @@ XMLHttpRequest = window.XMLHttpRequest;

var API_URL = 'https://api.github.com';
var Github = function(options) {
var API_URL = options.apiUrl || 'https://api.github.com';

@@ -47,3 +54,3 @@ // HTTP Request Abstraction

var url = path.indexOf('//') >= 0 ? path : API_URL + path;
return url + ((/\?/).test(url) ? "&" : "?") + (new Date()).getTime();
return url + ((/\?/).test(url) ? '&' : '?') + (new Date()).getTime();
}

@@ -57,3 +64,3 @@

xhr.onreadystatechange = function () {
if (this.readyState == 4) {
if (this.readyState === 4) {
if (this.status >= 200 && this.status < 300 || this.status === 304) {

@@ -69,3 +76,3 @@ cb(null, raw ? this.responseText : this.responseText ? JSON.parse(this.responseText) : true, this);

if (!raw) {
xhr.dataType = "json";
xhr.dataType = 'json';
xhr.setRequestHeader('Accept','application/vnd.github.v3+json');

@@ -81,7 +88,10 @@ } else {

}
if (data)
if (data) {
xhr.send(JSON.stringify(data));
else
} else {
xhr.send();
if (sync) return xhr.response;
}
if (sync) {
return xhr.response;
}
}

@@ -92,3 +102,3 @@

(function iterate() {
_request("GET", path, null, function(err, res, xhr) {
_request('GET', path, null, function(err, res, xhr) {
if (err) {

@@ -124,3 +134,3 @@ return cb(err);

// Github does not always honor the 1000 limit so we want to iterate over the data set.
_requestAllPages("/user/repos?type=all&per_page=1000&sort=updated", function(err, res) {
_requestAllPages('/user/repos?type=all&per_page=1000&sort=updated', function(err, res) {
cb(err, res);

@@ -134,3 +144,3 @@ });

this.orgs = function(cb) {
_request("GET", "/user/orgs", null, function(err, res) {
_request("GET", '/user/orgs', null, function(err, res) {
cb(err, res);

@@ -144,3 +154,3 @@ });

this.gists = function(cb) {
_request("GET", "/gists", null, function(err, res) {
_request("GET", '/gists', null, function(err, res) {
cb(err,res);

@@ -154,3 +164,3 @@ });

this.notifications = function(cb) {
_request("GET", "/notifications", null, function(err, res) {
_request("GET", '/notifications', null, function(err, res) {
cb(err,res);

@@ -164,5 +174,5 @@ });

this.show = function(username, cb) {
var command = username ? "/users/"+username : "/user";
var command = username ? '/users/' + username : '/user';
_request("GET", command, null, function(err, res) {
_request('GET', command, null, function(err, res) {
cb(err, res);

@@ -177,3 +187,3 @@ });

// Github does not always honor the 1000 limit so we want to iterate over the data set.
_requestAllPages("/users/"+username+"/repos?type=all&per_page=1000&sort=updated", function(err, res) {
_requestAllPages('/users/' + username + '/repos?type=all&per_page=1000&sort=updated', function(err, res) {
cb(err, res);

@@ -187,3 +197,3 @@ });

this.userGists = function(username, cb) {
_request("GET", "/users/"+username+"/gists", null, function(err, res) {
_request('GET', '/users/' + username + '/gists', null, function(err, res) {
cb(err,res);

@@ -198,3 +208,3 @@ });

// Github does not always honor the 1000 limit so we want to iterate over the data set.
_requestAllPages("/orgs/"+orgname+"/repos?type=all&&page_num=1000&sort=updated&direction=desc", function(err, res) {
_requestAllPages('/orgs/' + orgname + '/repos?type=all&&page_num=1000&sort=updated&direction=desc', function(err, res) {
cb(err, res);

@@ -208,3 +218,3 @@ });

this.follow = function(username, cb) {
_request("PUT", "/user/following/"+username, null, function(err, res) {
_request('PUT', '/user/following/' + username, null, function(err, res) {
cb(err, res);

@@ -218,3 +228,3 @@ });

this.unfollow = function(username, cb) {
_request("DELETE", "/user/following/"+username, null, function(err, res) {
_request('DELETE', '/user/following/' + username, null, function(err, res) {
cb(err, res);

@@ -227,3 +237,3 @@ });

this.createRepo = function(options, cb) {
_request("POST", "/user/repos", options, cb);
_request('POST', '/user/repos', options, cb);
};

@@ -241,7 +251,7 @@

var that = this;
var repoPath = "/repos/" + user + "/" + repo;
var repoPath = '/repos/' + user + '/' + repo;
var currentTree = {
"branch": null,
"sha": null
'branch': null,
'sha': null
};

@@ -254,3 +264,3 @@

this.deleteRepo = function(cb) {
_request("DELETE", repoPath, options, cb);
_request('DELETE', repoPath, options, cb);
};

@@ -262,4 +272,7 @@

function updateTree(branch, cb) {
if (branch === currentTree.branch && currentTree.sha) return cb(null, currentTree.sha);
that.getRef("heads/"+branch, function(err, sha) {
if (branch === currentTree.branch && currentTree.sha) {
return cb(null, currentTree.sha);
}
that.getRef('heads/' + branch, function(err, sha) {
currentTree.branch = branch;

@@ -275,4 +288,7 @@ currentTree.sha = sha;

this.getRef = function(ref, cb) {
_request("GET", repoPath + "/git/refs/" + ref, null, function(err, res) {
if (err) return cb(err);
_request('GET', repoPath + '/git/refs/' + ref, null, function(err, res) {
if (err) {
return cb(err);
}
cb(null, res.object.sha);

@@ -291,3 +307,3 @@ });

this.createRef = function(options, cb) {
_request("POST", repoPath + "/git/refs", options, cb);
_request('POST', repoPath + '/git/refs', options, cb);
};

@@ -302,3 +318,3 @@

this.deleteRef = function(ref, cb) {
_request("DELETE", repoPath + "/git/refs/"+ref, options, cb);
_request('DELETE', repoPath + '/git/refs/' + ref, options, cb);
};

@@ -310,3 +326,3 @@

this.createRepo = function(options, cb) {
_request("POST", "/user/repos", options, cb);
_request('POST', '/user/repos', options, cb);
};

@@ -318,3 +334,3 @@

this.deleteRepo = function(cb) {
_request("DELETE", repoPath, options, cb);
_request('DELETE', repoPath, options, cb);
};

@@ -326,4 +342,7 @@

this.listTags = function(cb) {
_request("GET", repoPath + "/tags", null, function(err, tags) {
if (err) return cb(err);
_request('GET', repoPath + '/tags', null, function(err, tags) {
if (err) {
return cb(err);
}
cb(null, tags);

@@ -337,3 +356,3 @@ });

this.listPulls = function(state, cb) {
_request("GET", repoPath + "/pulls" + (state ? '?state=' + state : ''), null, function(err, pulls) {
_request('GET', repoPath + "/pulls" + (state ? '?state=' + state : ''), null, function(err, pulls) {
if (err) return cb(err);

@@ -384,2 +403,12 @@ cb(null, pulls);

this.getCommit = function(branch, sha, cb) {
_request("GET", repoPath + "/git/commits/"+sha, null, function(err, commit) {
if (err) return cb(err);
cb(null, commit);
});
};
// For a given file path, get the corresponding sha (blob for files, tree for dirs)
// -------
this.getSha = function(branch, path, cb) {

@@ -488,3 +517,3 @@ if (!path || path === "") return that.getRef("heads/"+branch, cb);

this.updateHead = function(head, commit, cb) {
_request("PATCH", repoPath + "/git/refs/heads/" + head, { "sha": commit }, function(err, res) {
_request("PATCH", repoPath + "/git/refs/heads/" + head, { "sha": commit }, function(err) {
cb(err);

@@ -501,2 +530,23 @@ });

// Show repository contributors
// -------
this.contributors = function (cb, retry) {
retry = retry || 1000;
var self = this;
_request("GET", repoPath + "/stats/contributors", null, function (err, data, response) {
if (err) return cb(err);
if (response.status === 202) {
setTimeout(
function () {
self.contributors(cb, retry);
},
retry
);
} else {
cb(err, data);
}
});
};
// Get contents

@@ -506,3 +556,3 @@ // --------

this.contents = function(ref, path, cb) {
_request("GET", repoPath + "/contents/"+path, { ref: ref }, cb);
_request("GET", repoPath + "/contents" + (path ? "/" + path : ""), { ref: ref }, cb);
};

@@ -650,3 +700,3 @@

that.getSha(branch, path, function(err, sha) {
if (err && err.error!=404) return cb(err);
if (err && err.error !== 404) return cb(err);
_request("PUT", repoPath + "/contents/" + path, {

@@ -799,3 +849,9 @@ message: message,

this.list = function(options, cb) {
_request("GET", path, options, cb);
var query = [];
for (var key in options) {
if (options.hasOwnProperty(key)) {
query.push(encodeURIComponent(key) + "=" + encodeURIComponent(options[key]));
}
}
_requestAllPages(path + '?' + query.join("&"), cb);
};

@@ -824,5 +880,4 @@ };

/* istanbul ignore else */
if (typeof exports !== 'undefined') {
// Github = exports;
module.exports = Github;

@@ -829,0 +884,0 @@ } else {

{
"name": "github-api",
"version": "0.10.4",
"version": "0.10.6",
"description": "A higher-level wrapper around the Github API.",

@@ -13,7 +13,12 @@ "main": "github.js",

"devDependencies": {
"argg": "0.0.1",
"istanbul": "^0.3.13",
"jshint": "^2.5.8",
"tape": "^3.0.3"
"plato": "^1.4.0",
"tape": "^3.0.3",
"testling": "^1.7.1"
},
"scripts": {
"test": "tape test/test.*.js && jshint github.js test/*.js"
"test": "node node_modules/argg test/*.js && node node_modules/jshint/bin/jshint github.js test/*.js",
"jshint": "node node_modules/jshint/bin/jshint github.js test/*.js"
},

@@ -28,3 +33,7 @@ "repository": {

],
"author": "Sergey Klimov <sergey.v.klimov@gmail.com> (http://darvin.github.com/)",
"contributors": [
"Sergey Klimov <sergey.v.klimov@gmail.com> (http://darvin.github.com/)",
"Michael Aufreiter (http://substance.io)",
"Ændrew Rininsland <aendrew.rininsland@thetimes.co.uk> (http://www.aendrew.com)"
],
"license": "BSD",

@@ -34,3 +43,3 @@ "readmeFilename": "README.md",

"bugs": {
"url": "https://github.com/darvin/github/issues"
"url": "https://github.com/michael/github/issues"
},

@@ -37,0 +46,0 @@ "browser": {

@@ -1,10 +0,5 @@

[![browser support](https://ci.testling.com/darvin/github.png)](https://ci.testling.com/darvin/github)
# Github.js
[![Stories in Ready](https://badge.waffle.io/michael/github.png?label=ready&title=Ready)](https://waffle.io/michael/github)[![Build Status](https://travis-ci.org/darvin/github.svg?branch=master)](https://travis-ci.org/darvin/github)[![Coverage Status](https://img.shields.io/coveralls/michael/github.svg)](https://coveralls.io/r/michael/github)
[![Build Status](https://travis-ci.org/darvin/github.png?branch=master)](https://travis-ci.org/darvin/github)
[![Coverage Status](https://img.shields.io/coveralls/michael/github.svg)](https://coveralls.io/r/michael/github)
# Github.js
Github.js provides a minimal higher-level wrapper around git's [plumbing commands](http://git-scm.com/book/en/Git-Internals-Plumbing-and-Porcelain), exposing an API for manipulating GitHub repositories on the file level. It is being developed in the context of [Prose](http://prose.io), a content editor for GitHub.

@@ -53,2 +48,11 @@

Enterprise Github instances may be specified using the `apiUrl` option:
```js
var github = new Github({
apiUrl: "https://serverName/api/v3",
...
});
```
## Repository API

@@ -73,6 +77,6 @@

Get contents at a particular path in a particular branch. Set sync to true to get contents via sync method.
Get contents at a particular path in a particular branch.
```js
repo.contents(branch, "path/to/dir", function(err, contents) {}, sync);
repo.contents(branch, "path/to/dir", function(err, contents) {});
```

@@ -138,2 +142,8 @@

```js
repo.getCommit('master', sha, function(err, commit) {});
```
Get information about a particular commit.
```js
repo.getTree('master', function(err, tree) {});

@@ -176,3 +186,8 @@ ```

Get contributors list with additions, deletions, and commit counts.
```js
repo.contributors(function(err, data) {});
```
## User API

@@ -306,2 +321,6 @@

## Compatibility
[![browser support](https://ci.testling.com/darvin/github.png)](https://ci.testling.com/darvin/github)
## Change Log

@@ -312,2 +331,3 @@

Create and delete repositories
Repos - getCommit

@@ -314,0 +334,0 @@ ### 0.9.X

@@ -1,2 +0,4 @@

var test = require('tape');
'use strict';
var test = require('tape'); //jshint ignore:line
var Github = require("../");

@@ -6,36 +8,35 @@ var test_user = require('./user.json');

test("Basic Auth - Pass", function(t) {
var timeout = setTimeout(function () { t.fail(); }, 10000);
var github = new Github({
username: test_user.USERNAME,
password: test_user.PASSWORD,
auth: "basic"
});
var user = github.getUser();
user.notifications(function(err, res) {
t.error(err, 'user is authd');
});
clearTimeout(timeout);
t.end();
var timeout = setTimeout(function () { t.fail(); }, 10000);
var github = new Github({
username: test_user.USERNAME,
password: test_user.PASSWORD,
auth: "basic"
});
var user = github.getUser();
user.notifications(function(err) {
t.error(err, 'user is authd');
});
clearTimeout(timeout);
t.end();
});
test("Basic Auth - Fail", function(t) {
var timeout = setTimeout(function () { t.fail(); }, 10000);
var github = new Github({
username: test_user.USERNAME,
password: 'fake124',
auth: "basic"
});
var user = github.getUser();
var timeout = setTimeout(function () { t.fail(); }, 10000);
var github = new Github({
username: test_user.USERNAME,
password: 'fake124',
auth: "basic"
});
var user = github.getUser();
user.notifications(function(err, res) {
t.ok(err, 'user is not authd');
t.equals(JSON.parse(err.request.responseText).message, 'Bad credentials', 'confirm error');
});
user.notifications(function(err) {
t.ok(err, 'user is not authd');
t.equals(JSON.parse(err.request.responseText).message, 'Bad credentials', 'confirm error');
});
clearTimeout(timeout);
t.end();
clearTimeout(timeout);
t.end();
});

@@ -1,2 +0,4 @@

var test = require('tape');
'use strict';
var test = require('tape'); //jshint ignore:line
var Github = require("../");

@@ -23,3 +25,3 @@ var test_user = require('./user.json');

t.test('repo.contents', function(q) {
repo.contents('master', './', function(err, res) {
repo.contents('master', './', function(err) {
q.error(err, 'get repo contents');

@@ -31,3 +33,3 @@ q.end();

t.test('repo.fork', function(q) {
repo.fork(function(err, res) {
repo.fork(function(err) {
q.error(err, 'test fork repo');

@@ -38,6 +40,18 @@ q.end();

t.test('repo.contributors', function(q) {
repo.contributors(function(err, res) {
q.error(err, 'repo contributors');
q.ok(res instanceof Array, 'list of contributors');
q.ok(res.length, 'at least one contributor');
q.ok(res[0].author, 'contributor info');
q.ok(res[0].total, 'total number of commits');
q.ok(res[0].weeks, 'weekly hash');
q.end();
});
});
//@TODO repo.branch, repo.pull
t.test('repo.listBranches', function(q) {
repo.listBranches(function(err, res) {
repo.listBranches(function(err) {
q.error(err, 'list branches');

@@ -55,2 +69,11 @@ q.end();

t.test('repo.getCommit', function(q) {
repo.getCommit('master', '20fcff9129005d14cc97b9d59b8a3d37f4fb633b', function(err, commit) {
q.error(err, 'get commit' + err);
q.ok(commit.message, 'v0.10.4', 'Returned commit message.');
q.ok(commit.author.date, '2015-03-20T17:01:42Z', 'Got correct date.');
q.end();
});
});
clearTimeout(timeout);

@@ -64,64 +87,62 @@ t.end();

test('Create Repo', function(t) {
var timeout = setTimeout(function () { t.fail(); }, 10000);
var github = new Github({
username: test_user.USERNAME,
password: test_user.PASSWORD,
auth: "basic"
});
var user = github.getUser();
var timeout = setTimeout(function () { t.fail(); }, 10000);
var github = new Github({
username: test_user.USERNAME,
password: test_user.PASSWORD,
auth: "basic"
});
var user = github.getUser();
t.test('user.createRepo', function(q) {
user.createRepo({ "name": repoTest }, function (err, res) {
q.error(err);
q.equals(res.name, repoTest.toString(), 'Repo created');
q.end();
});
t.test('user.createRepo', function(q) {
user.createRepo({ "name": repoTest }, function (err, res) {
q.error(err);
q.equals(res.name, repoTest.toString(), 'Repo created');
q.end();
});
var repo = github.getRepo(test_user.USERNAME, repoTest);
});
var repo = github.getRepo(test_user.USERNAME, repoTest);
t.test('repo.write', function(q) {
repo.write('master', 'TEST.md', 'THIS IS A TEST', 'Creating test', function(err) {
q.error(err);
q.end();
});
t.test('repo.write', function(q) {
repo.write('master', 'TEST.md', 'THIS IS A TEST', 'Creating test', function(err) {
q.error(err);
q.end();
});
clearTimeout(timeout);
t.end();
});
clearTimeout(timeout);
t.end();
});
test('delete Repo', function(t) {
var timeout = setTimeout(function () { t.fail(); }, 10000);
var github = new Github({
username: test_user.USERNAME,
password: test_user.PASSWORD,
auth: "basic"
});
var repo = github.getRepo(test_user.USERNAME, repoTest);
repo.deleteRepo(function(err, res) {
t.error(err);
t.equals(res, true, 'Repo Deleted');
clearTimeout(timeout);
t.end();
});
var timeout = setTimeout(function () { t.fail(); }, 10000);
var github = new Github({
username: test_user.USERNAME,
password: test_user.PASSWORD,
auth: "basic"
});
var repo = github.getRepo(test_user.USERNAME, repoTest);
repo.deleteRepo(function(err, res) {
t.error(err);
t.equals(res, true, 'Repo Deleted');
clearTimeout(timeout);
t.end();
});
});
test('Repo Returns commit errors correctly', function(t) {
var timeout = setTimeout(function () { t.fail(); }, 10000);
var github = new Github({
username: test_user.USERNAME,
password: test_user.PASSWORD,
auth: "basic"
});
var repo = github.getRepo(test_user.USERNAME, test_user.REPO);
var timeout = setTimeout(function () { t.fail(); }, 10000);
var github = new Github({
username: test_user.USERNAME,
password: test_user.PASSWORD,
auth: "basic"
});
var repo = github.getRepo(test_user.USERNAME, test_user.REPO);
repo.commit("broken-parent-hash", "broken-tree-hash", "commit message", function(err){
t.ok(err, 'error thrown for bad commit');
t.ok(err.request);
t.equals(err.request.status, 422, 'Returns 422 status');
clearTimeout(timeout);
t.end();
});
repo.commit("broken-parent-hash", "broken-tree-hash", "commit message", function(err){
t.ok(err, 'error thrown for bad commit');
t.ok(err.request);
t.equals(err.request.status, 422, 'Returns 422 status');
clearTimeout(timeout);
t.end();
});
});

@@ -1,2 +0,4 @@

var test = require('tape');
'use strict';
var test = require('tape'); //jshint ignore:line
var Github = require("../");

@@ -6,76 +8,75 @@ var test_user = require('./user.json');

test("User API", function(t) {
var timeout = setTimeout(function () { t.fail(); }, 100000);
var github = new Github({
username: test_user.USERNAME,
password: test_user.PASSWORD,
auth: "basic"
});
var user = github.getUser();
var timeout = setTimeout(function () { t.fail(); }, 100000);
var github = new Github({
username: test_user.USERNAME,
password: test_user.PASSWORD,
auth: "basic"
});
var user = github.getUser();
t.test('user.orgs', function(q) {
user.orgs(function(err, res) {
q.error(err, 'user orgs');
q.end();
});
t.test('user.orgs', function(q) {
user.orgs(function(err) {
q.error(err, 'user orgs');
q.end();
});
});
t.test('user.gists', function(q) {
user.gists(function(err, res) {
q.error(err, 'user gists');
q.end();
});
t.test('user.gists', function(q) {
user.gists(function(err) {
q.error(err, 'user gists');
q.end();
});
});
t.test('user.notifications', function(q) {
user.notifications(function(err, res) {
q.error(err, 'user notifications');
q.end();
});
t.test('user.notifications', function(q) {
user.notifications(function(err) {
q.error(err, 'user notifications');
q.end();
});
});
t.test('user.show', function(q) {
user.show('ingalls', function(err, res) {
q.error(err, 'user show');
q.end();
});
t.test('user.show', function(q) {
user.show('ingalls', function(err) {
q.error(err, 'user show');
q.end();
});
});
t.test('user.userRepos', function(q) {
user.userRepos(test_user.USERNAME, function(err, res) {
q.error(err, 'alt user repos');
q.end();
});
t.test('user.userRepos', function(q) {
user.userRepos(test_user.USERNAME, function(err) {
q.error(err, 'alt user repos');
q.end();
});
});
t.test('user.userGists', function(q) {
user.userGists(test_user.USERNAME, function(err, res) {
q.error(err, 'alt user gists');
q.end();
});
t.test('user.userGists', function(q) {
user.userGists(test_user.USERNAME, function(err) {
q.error(err, 'alt user gists');
q.end();
});
});
t.test('user.orgRepos', function(q) {
user.orgRepos('openaddresses', function(err, res) {
q.error(err, 'org users');
q.end();
});
t.test('user.orgRepos', function(q) {
user.orgRepos('openaddresses', function(err) {
q.error(err, 'org users');
q.end();
});
});
t.test('user.follow', function(q) {
user.follow('ingalls', function(err, res) {
q.error(err, 'follow ingalls');
q.end();
});
t.test('user.follow', function(q) {
user.follow('ingalls', function(err) {
q.error(err, 'follow ingalls');
q.end();
});
});
t.test('user.unfollow', function(q) {
user.unfollow('ingalls', function(err, res) {
q.error(err, 'unfollow ingalls');
q.end();
});
t.test('user.unfollow', function(q) {
user.unfollow('ingalls', function(err) {
q.error(err, 'unfollow ingalls');
q.end();
});
});
clearTimeout(timeout);
t.end();
clearTimeout(timeout);
t.end();
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc