Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,10 @@ issues.list(options, function(err, issues) {});

##Setup

Github.js has the following dependencies:
Github.js has the following dependency:

- Underscore
- btoa (included in modern browsers, an npm module is included in package.json for node)

Include these before github.js :

```
<script src="lib/underscore-min.js">
<script src="github.js">
```

## Compatibility

Expand Down
22 changes: 13 additions & 9 deletions github.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@
// Initial Setup
// -------------

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

Expand All @@ -50,9 +48,9 @@
var url = path.indexOf('//') >= 0 ? path : API_URL + path;
url += ((/\?/).test(url) ? '&' : '?');
// Fix #195 about XMLHttpRequest.send method and GET/HEAD request
if (_.isObject(data) && _.indexOf(['GET', 'HEAD'], method) > -1) {
url += '&' + _.map(data, function (v, k) {
return k + '=' + v;
if (data && typeof data === "object" && ['GET', 'HEAD'].indexOf(method) > -1) {
url += '&' + Object.keys(data).map(function (k) {
return k + '=' + data[k];
}).join('&');
}
return url + '&' + (new Date()).getTime();
Expand Down Expand Up @@ -107,7 +105,10 @@
results.push.apply(results, res);

var links = (xhr.getResponseHeader('link') || '').split(/\s*,\s*/g),
next = _.find(links, function(link) { return /rel="next"/.test(link); });
next = null;
links.forEach(function(link) {
next = /rel="next"/.test(link) ? link : next;
});

if (next) {
next = (/<(.*)>/.exec(next) || [])[1];
Expand Down Expand Up @@ -364,7 +365,10 @@
this.listBranches = function(cb) {
_request("GET", repoPath + "/git/refs/heads", null, function(err, heads) {
if (err) return cb(err);
cb(null, _.map(heads, function(head) { return _.last(head.ref.split('/')); }));
cb(null, heads.map(function(head) {
var headParts = head.ref.split('/');
return headParts[headParts.length - 1];
}));
});
};

Expand Down Expand Up @@ -651,7 +655,7 @@
updateTree(branch, function(err, latestCommit) {
that.getTree(latestCommit+"?recursive=true", function(err, tree) {
// Update Tree
_.each(tree, function(ref) {
tree.forEach(function(ref) {
if (ref.path === path) ref.path = newPath;
if (ref.type === "tree") delete ref.sha;
});
Expand Down
5 changes: 0 additions & 5 deletions lib/underscore-min.js

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"dependencies": {
"atob": "^1.1.2",
"btoa": "^1.1.2",
"underscore": "~1.8.3",
"xmlhttprequest": "~1.7.0"
},
"devDependencies": {
Expand Down