Created
March 9, 2017 19:46
-
-
Save trieloff/168312d4dd4d149afdd55cde3d3724ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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