Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pull down all the github repos for a user
var request = require('request');
var JSONStream = require('JSONStream');
var stringify = JSONStream.stringify();
stringify.pipe(process.stdout);
var user = process.argv[2];
if (!user) return;
(function getPage (uri) {
request(uri).on('response', function (res) {
var parse = JSONStream.parse([ /./ ]);
res.pipe(parse, { end : false });
parse.on('data', function (row) {
stringify.write(row);
});
var ratelimit = res.headers['x-ratelimit-limit'] || 5000;
var m = /<([^>]+)>;\s*rel="next"/.exec(res.headers.link);
if (m) {
var nextPage = m[1];
res.on('end', function () {
setTimeout(function () {
getPage(nextPage);
}, ratelimit);
});
}
else stringify.end();
});
})('https://api.github.com/users/' + user + '/repos');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.