Skip to content

Commit

Permalink
Merge pull request twitter#8 from bensheldon/master
Browse files Browse the repository at this point in the history
Load all repos from API (not just just first 30)
  • Loading branch information
caniszczyk committed Jul 24, 2012
2 parents 5dca233 + d4981e4 commit 7599209
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 46 deletions.
Binary file added assets/spinner.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 60 additions & 46 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,51 +63,65 @@
$item.appendTo("#repos");
}

$.getJSON("https://api.github.com/orgs/twitter/repos?callback=?", function (result) {
var repos = result.data;

$(function () {
$("#num-repos").text(repos.length);

// Convert pushed_at to Date.
$.each(repos, function (i, repo) {
repo.pushed_at = new Date(repo.pushed_at);

var weekHalfLife = 1.146 * Math.pow(10, -9);

var pushDelta = (new Date) - Date.parse(repo.pushed_at);
var createdDelta = (new Date) - Date.parse(repo.created_at);

var weightForPush = 1;
var weightForWatchers = 1.314 * Math.pow(10, 7);

repo.hotness = weightForPush * Math.pow(Math.E, -1 * weekHalfLife * pushDelta);
repo.hotness += weightForWatchers * repo.watchers / createdDelta;
});

// Sort by highest # of watchers.
repos.sort(function (a, b) {
if (a.hotness < b.hotness) return 1;
if (b.hotness < a.hotness) return -1;
return 0;
});

$.each(repos, function (i, repo) {
addRepo(repo);
});

// Sort by most-recently pushed to.
repos.sort(function (a, b) {
if (a.pushed_at < b.pushed_at) return 1;
if (b.pushed_at < a.pushed_at) return -1;
return 0;
});

$.each(repos.slice(0, 3), function (i, repo) {
addRecentlyUpdatedRepo(repo);
});
function addRepos(repos, page) {
repos = repos || [];
page = page || 1;

var uri = "https://api.github.com/orgs/twitter/repos?callback=?"
+ "&per_page=100"
+ "&page="+page;

$.getJSON(uri, function (result) {
if (result.data && result.data.length > 0) {
repos = repos.concat(result.data);
addRepos(repos, page + 1);
}
else {
$(function () {
$("#num-repos").text(repos.length);

// Convert pushed_at to Date.
$.each(repos, function (i, repo) {
repo.pushed_at = new Date(repo.pushed_at);

var weekHalfLife = 1.146 * Math.pow(10, -9);

var pushDelta = (new Date) - Date.parse(repo.pushed_at);
var createdDelta = (new Date) - Date.parse(repo.created_at);

var weightForPush = 1;
var weightForWatchers = 1.314 * Math.pow(10, 7);

repo.hotness = weightForPush * Math.pow(Math.E, -1 * weekHalfLife * pushDelta);
repo.hotness += weightForWatchers * repo.watchers / createdDelta;
});

// Sort by highest # of watchers.
repos.sort(function (a, b) {
if (a.hotness < b.hotness) return 1;
if (b.hotness < a.hotness) return -1;
return 0;
});

$.each(repos, function (i, repo) {
addRepo(repo);
});

// Sort by most-recently pushed to.
repos.sort(function (a, b) {
if (a.pushed_at < b.pushed_at) return 1;
if (b.pushed_at < a.pushed_at) return -1;
return 0;
});

$.each(repos.slice(0, 3), function (i, repo) {
addRecentlyUpdatedRepo(repo);
});
});
}
});
});
}
addRepos();

$.getJSON("https://api.github.com/orgs/twitter/members?callback=?", function (result) {
var members = result.data;
Expand Down Expand Up @@ -220,9 +234,9 @@ <h1>Twitter is built on open source software.</h1>
<div id="statistics" class="grid-1 alpha header">
<h1>Statistics</h1>
<p>
<a href="https://github.com/twitter/repositories"><span id="num-repos">&nbsp;</span> public repos</a>
<a href="https://github.com/twitter/repositories"><span id="num-repos"><img src="assets/spinner.gif" /></span> public repos</a>
<br>
<a href="https://github.com/twitter"><span id="num-members">&nbsp;</span> members</a>
<a href="https://github.com/twitter"><span id="num-members"><img src="assets/spinner.gif" /></span> members</a>
</p>
<p class="email"><a href="mailto:opensource@twitter.com">opensource@twitter.com</a></p>
</div>
Expand Down

0 comments on commit 7599209

Please sign in to comment.