JSFiddle - React, Tailwind, and code Playground
by groovecoder
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<ul id="contributors">
</ul>
JavaScript
var repos = ['bedrock', 'kuma', 'kitsune', 'zamboni', 'socorro', 'mozillians', 'remo', 'input.mozilla.org', 'django-browserid'],
levels = [10, 25, 50, 100],
base_url = "https://api.github.com/repos/mozilla/",
ajaxRequests = [],
contributors = {};
function addContributions(data) {
_.each(data, function(contributor) {
var name = contributor.login;
if (contributors[name]) {
contributors[name] += contributor['contributions'];
} else {
contributors[name] = contributor['contributions'];
}
});
}
for (var i=0; i < repos.length; i++) {
var repo_url = base_url + repos[i] + "/contributors";
var getting_json = $.getJSON(repo_url, addContributions);
ajaxRequests.push(getting_json);
console.log(ajaxRequests);
}
function countLevel(contributors, num_commits) {
level_contributors = _.filter(contributors, function(contributions){
return contributions > num_commits;
});
return _.size(level_contributors);
}
var defer = $.when.apply($, ajaxRequests);
defer.done(function(args){
console.log("Contributors: " + _.size(contributors));
_.each(levels, function(level){
console.log(level + "+ contributors: " + countLevel(contributors, level));
});
});