Skip to content

Instantly share code, notes, and snippets.

@trieloff
Created March 9, 2017 19:46
Show Gist options
  • Save trieloff/168312d4dd4d149afdd55cde3d3724ca to your computer and use it in GitHub Desktop.
Save trieloff/168312d4dd4d149afdd55cde3d3724ca to your computer and use it in GitHub Desktop.
var github = {
getUserRepos: function(uri, repos) {
return request({
"method": "GET",
"uri": uri,
"json": true,
"resolveWithFullResponse": true,
"headers": {
"Authorization": "Bearer " + github.token,
"User-Agent": "My little demo app"
}
}).then(function(response) {
if (!repos) {
repos = [];
}
repos = repos.concat(response.body);
console.log(repos.length + " repos so far");
if (response.headers.link.split(",").filter(function(link){ return link.match(/rel="next"/) }).length > 0) {
console.log("There is more.");
var next = new RegExp(/<(.*)>/).exec(response.headers.link.split(",").filter(function(link){ return link.match(/rel="next"/) })[0])[1];
return github.getUserRepos(next, repos);
}
return repos;
});
}
}
function main(params) {
github.token = params.token;
return github.getUser()
.then(github.getUserReposUrl)
.then(github.getUserRepos);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment