Skip to content

Instantly share code, notes, and snippets.

@mixu
Created February 22, 2013 21:25
Show Gist options
  • Save mixu/5016664 to your computer and use it in GitHub Desktop.
Save mixu/5016664 to your computer and use it in GitHub Desktop.
Repo fetching
(function() {
var repos = [];
function parse_link_header(header) {
// Split parts by comma
var parts = (header ? header.split(',') : []),
links = {};
// Parse each part into a named link
parts.forEach(function(p) {
var section = p.split(';');
if (section.length != 2) {
throw new Error("section could not be split on ';'");
}
var url = section[0].replace(/<(.*)>/, '$1').trim();
var name = section[1].replace(/rel="(.*)"/, '$1').trim();
links[name] = url;
});
return links;
}
function fetch(url) {
var jq = $.get(url, function(data) {
data.sort(function(a,b) { return a.name.localeCompare(b.name); }).forEach(function(repo) { console.log(repo.name); })
repos = repos.concat(data);
var headers = parse_link_header(jq.getResponseHeader('link'));
if(headers.next) {
fetch(headers.next);
} else {
onDone();
}
});
}
function onDone() {
repos
.sort(function(a,b) { return a.name.localeCompare(b.name); })
// .sort(function(a,b) { return new Date(a.updated_at) - new Date(b.updated_at); })
.forEach(function(repo) {
console.log(repo.name + ' | '+(repo["private"] ? 'private' : 'public')+' | '+repo.updated_at+' | size: '+repo.size+' | '+repo.description);
});
window.repos = repos;
}
fetch('https://api.github.com/orgs/foo/repos?type=all&scope=repo');
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment