fetch all repos

This commit is contained in:
Oscar Del Ben
2011-03-23 08:59:24 +01:00
parent e0d1a17c83
commit 1c2d71c9ef
3 changed files with 41 additions and 25 deletions

View File

@@ -215,20 +215,46 @@
return this;
};
// Get a list of this user's repositories.
// Get a list of this user's repositories, 30 per page
//
// gh.user("fitzgen").repos(function (data) {
// alert(data.repositories.length);
// });
gh.user.prototype.repos = function (callback, context) {
gh.repo.forUser(this.username, callback, context);
gh.user.prototype.repos = function (callback, context, page) {
gh.repo.forUser(this.username, callback, context, page);
return this;
};
gh.user.prototype.orgs = function (callback, context) {
gh.org.forUser(this.username, callback, context);
return this;
};
// Get a list of all repos for this user.
//
// gh.user("fitzgen").allRepos(function (repos) {
// alert(repos.length);
// });
gh.user.prototype.allRepos = function(callback, context) {
var repos = [];
var username = this.username;
var page = 1;
var exitCallback = function (repos) { callback.call(context, { repositories: repos }) };
var pageLoop = function (data) {
repos = repos.concat(data.repositories);
var reposLength = data.repositories.length;
if (reposLength == 0) {
exitCallback(repos);
}
else {
page += 1;
gh.repo.forUser(username, pageLoop, context, page);
}
}
gh.repo.forUser(username, pageLoop, context, page);
return this;
}
// Make this user fork the repo that lives at
// http://github.com/user/repo. You must be authenticated as this user for
@@ -276,15 +302,6 @@
this.user = user;
};
gh.org = function(user, org) {
if (!(this instanceof gh.org)) {
return new gh.org(user, org);
}
this.org = org;
this.user = user;
};
// Get basic information on this repo.
//
// gh.repo("schacon", "grit").show(function (data) {
@@ -412,13 +429,11 @@
};
// Get all the repos that are owned by `user`.
gh.repo.forUser = function (user, callback, context) {
jsonp("repos/show/" + user, callback, context);
return this;
};
gh.repo.forUser = function (user, callback, context, page) {
if (!page)
page = 1;
gh.org.forUser = function (user, callback, context) {
jsonp("user/show/" + user + "/organizations", callback, context);
jsonp("repos/show/" + user + '?page=' + page, callback, context);
return this;
};
@@ -684,3 +699,4 @@
);
}(window));

View File

@@ -59,7 +59,7 @@ var run = function() {
var itemCount = 0, maxItems = 5, maxLanguages = 9;
var res = gh_user.show(function(data) {
gh_user.repos(function(data) {
gh_user.allRepos(function(data) {
repos = data;
});
@@ -106,7 +106,7 @@ var run = function() {
});
});
gh_user.repos(function(data) {
gh_user.allRepos(function(data) {
var repos = data.repositories;
var sorted = [];

View File

@@ -52,7 +52,7 @@
<br /><br />
<h2>Notes, Information and Future features</h2>
<p class="enlarge-medium"><br />
This is the first version, please keep in mind that it only fetches your first 30 repositories for now. I am planning on adding
This is the first version. I am planning on adding
things as such as your most committed forks, most committed repositories and make the "My Popular Repositories" be built from
your complete list of repositories. The issue right now is say you have 37 repositories, this will only retrieve the first
30 repositories that were created. I'll put a note here when this is fixed or feel free to <a href="https://github.com/resume/resume.github.com">fork the page</a>,