Skip to content
This repository was archived by the owner on Feb 18, 2024. It is now read-only.
Closed
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
66 changes: 0 additions & 66 deletions exec-git.js

This file was deleted.

92 changes: 35 additions & 57 deletions github.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ try {
}
catch(e) {}

var execGit = require('./exec-git');

function createRemoteStrings(auth, hostname) {
var authString = auth.username ? (encodeURIComponent(auth.username) + ':' + encodeURIComponent(auth.password) + '@') : '';
hostname = hostname || 'github.com';
Expand Down Expand Up @@ -112,32 +110,15 @@ var GithubLocation = function(options, ui) {

this.ui = ui;

this.execOpt = {
cwd: options.tmpDir,
timeout: options.timeout * 1000,
killSignal: 'SIGKILL',
maxBuffer: this.max_repo_size || 2 * 1024 * 1024,
env: extend({}, process.env)
};

this.defaultRequestOptions = {
strictSSL: 'strictSSL' in options ? options.strictSSL : true
};

if (!this.defaultRequestOptions.strictSSL) {
this.execOpt.env.GIT_SSL_NO_VERIFY = '1'
}

var self = this, envMap = {
ca: 'GIT_SSL_CAINFO',
cert: 'GIT_SSL_CERT',
key: 'GIT_SSL_KEY'
};
var self = this;

['ca', 'cert', 'key'].forEach(function(key) {
if (key in options) {
var path = expandTilde(options[key]);
self.execOpt.env[envMap[key]] = path;
self.defaultRequestOptions[key] = fs.readFileSync(path, 'ascii');
}
});
Expand Down Expand Up @@ -338,44 +319,40 @@ GithubLocation.prototype = {
// { versions: { versionhash } }
// { notfound: true }
lookup: function(repo) {
var execOpt = this.execOpt;
var remoteString = this.remoteString;
return new Promise(function(resolve, reject) {
execGit('ls-remote ' + remoteString.replace(/(['"()])/g, '\\\$1') + repo + '.git refs/tags/* refs/heads/*', execOpt, function(err, stdout, stderr) {
if (err) {
if (err.toString().indexOf('not found') == -1) {
var error = new Error(stderr);
error.hideStack = true;
error.retriable = true;
reject(error);
}
else
resolve({ notfound: true });
}
var remoteString = this.apiRemoteString;
var authSuffix = this.authSuffix;

versions = {};
var refs = stdout.split('\n');
for (var i = 0; i < refs.length; i++) {
if (!refs[i])
continue;
var promises = ['heads', 'tags'].map(function(scope) {
return asp(request)(extend({
uri: remoteString + 'repos/' + repo + '/git/refs/' + scope + authSuffix,
headers: {
'User-Agent': 'jspm',
'Accept': 'application/vnd.github.v3.raw'
},
}, this.defaultRequestOptions
));
});

return Promise.all(promises).then(function(values) {
var versions = {};

var hash = refs[i].substr(0, refs[i].indexOf('\t'));
var refName = refs[i].substr(hash.length + 1);
values.forEach(function(res) {
JSON.parse(res.body).forEach(function(entry) {
var hash = entry.object.sha;
var refName = entry.ref;
var version;
var versionObj = { hash: hash, meta: {} };

if (refName.substr(0, 11) == 'refs/heads/') {
version = refName.substr(11);
if (refName.startsWith('refs/heads/')) {
version = refName.substr('refs/heads/'.length);
versionObj.stable = false;
}

else if (refName.substr(0, 10) == 'refs/tags/') {
if (refName.substr(refName.length - 3, 3) == '^{}')
version = refName.substr(10, refName.length - 13);
} else if (refName.startsWith('refs/tags/')) {
if (refName.endsWith('^{}'))
version = refName.substr('refs/tags/'.length, refName.length - 13); // TODO: what is this "13"?
else
version = refName.substr(10);
version = refName.substr('refs/tags/'.length);

if (version.substr(0, 1) == 'v' && semver.valid(version.substr(1))) {
if (version.startsWith('v') && semver.valid(version.substr(1))) {
version = version.substr(1);
// note when we remove a "v" which versions we need to add it back to
// to work out the tag version again
Expand All @@ -384,10 +361,12 @@ GithubLocation.prototype = {
}

versions[version] = versionObj;
}
})
})

resolve({ versions: versions });
});
return { versions: versions };
}).catch(function(reason) {
return { notfound: true };
});
},

Expand Down Expand Up @@ -420,14 +399,14 @@ GithubLocation.prototype = {
+ (showAuthCommand ? '\nTo resolve use %jspm registry config github% to configure the credentials, or update them in your ~/.netrc file.' : ''));
apiWarned = true;
}

if (res.headers.status.match(/^401/))
return apiFailWarn('lack of authorization', true);
if (res.headers.status.match(/^406/))
return apiFailWarn('insufficient permissions. Ensure you have public_repo access.');
if (res.headers['x-ratelimit-remaining'] == '0') {
if (self.auth)
return apiFailWarn('the rate limit being reached, which will be reset in `' +
return apiFailWarn('the rate limit being reached, which will be reset in `' +
Math.round((res.headers['x-ratelimit-reset'] * 1000 - new Date(res.headers.date).getTime()) / 60000) + ' minutes`.');
return apiFailWarn('the rate limit being reached.', true);
}
Expand Down Expand Up @@ -456,7 +435,7 @@ GithubLocation.prototype = {

var self = this;

if ((packageConfig.dependencies || packageConfig.peerDependencies || packageConfig.optionalDependencies) &&
if ((packageConfig.dependencies || packageConfig.peerDependencies || packageConfig.optionalDependencies) &&
!packageConfig.registry && (!packageConfig.jspm || !(packageConfig.jspm.dependencies || packageConfig.jspm.peerDependencies || packageConfig.jspm.optionalDependencies))) {
var hasDependencies = false;
for (var p in packageConfig.dependencies)
Expand Down Expand Up @@ -534,7 +513,6 @@ GithubLocation.prototype = {
if (meta.vPrefix)
version = 'v' + version;

var execOpt = this.execOpt;
var max_repo_size = this.max_repo_size;
var remoteString = this.remoteString;
var authSuffix = this.authSuffix;
Expand Down
35 changes: 0 additions & 35 deletions test/pool.js

This file was deleted.