Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
253 lines (221 sloc) 8.04 KB
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
ul.projects
{
font-size: 1em;
color: #000;
font-family: Arial;
display: table-row;
}
ul.projects, ul.issues {
list-style-type: none;
padding: 0;
margin: 0;
}
ul.toggleable {
display: none;
}
ul.projects > li > ul.histogram {
cursor: pointer;
}
ul.histogram {
display: inline-block;
margin-right: 10px;
margin-left: 0px;
padding: 0px;
}
ul.histogram li {
display: inline-block;
width: 10px;
height: 10px;
margin-left: 2px;
}
ul.histogram li.quartile-0 {
background-color: #eee;
}
ul.histogram li.quartile-1 {
background-color: #d6e685;
}
ul.histogram li.quartile-2 {
background-color: #8cc665;
}
ul.histogram li.quartile-3 {
background-color: #44a340;
}
ul.histogram li.quartile-4 {
background-color: #1e6823;
}
span.issue {
margin-left: 20px;
font-size: 80%;
}
span.project {
}
a {
color: #4078c0;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.2.min.js"></script>
<script>
$(document).ready(function() {
var bitbucketRssUrl = "https://bitbucket.org/jimmykeen/rss/feed?token=c28ef6fb97fd2004c50d35354bf0850f";
var bitbucketUserName = /bitbucket\.org\/([^\/]+)\/rss/.exec(bitbucketRssUrl)[1];
var createActivities = function(userName, bitbucketRssData) {
var createActionActivity = function (title) {
var match = /([a-z]+)(?: on)? issue #([0-9]+) in (.+)/.exec(title);
return {
action: match[1],
project: match[3],
issue: match[2],
};
};
var createCommitActivity = function (commitElement, project) {
var commitText = $(commitElement).text();
var match = /#([0-9]+)/.exec(commitText);
return match == null
? { action: "pushed", project: project }
: { action: "pushed", project: project, issue: match[1] };
};
var createActivity = function * (userName, element) {
var title = $(element).children("title").text().replace(/^\s+|\s+$/gm,'');
var isAction = function(action) { return title.startsWith(userName + " " + action); };
var isNonCommitAction = isAction("commented") || isAction("reported") || isAction("updated");
if (isNonCommitAction) {
yield createActionActivity(title);
}
else if (isAction("pushed")) {
var match = /pushed [0-9]+ commits? to (.+)/.exec(title);
var descriptionRawEncodedHtml = $(element).children("description").text();
var commitDetails = $("<div/>")
.html(descriptionRawEncodedHtml)
.find("li")
.map(function () { return createCommitActivity(this, match[1]); });
for (var commit of commitDetails) {
yield commit;
}
}
else {
yield { action: "unknown" };
}
};
return $(bitbucketRssData)
.find("item")
.map(function () { return createActivity(userName, this); })
.map(function () { return Array.from(this); })
.toArray();
};
var createProjectGroups = function (activities) {
var createProjectGroup = function(activity) {
var projectGroup = {
project: activity.project,
activities: [activity],
issues: []
};
if (activity.issue != undefined) {
projectGroup.issues.push({ name: activity.issue, contributions: 1 });
}
return projectGroup;
};
var updateIssue = function (projectGroup, issue) {
var existingIssue = projectGroup.issues.find(function (i) { return i.name == issue; });
if (existingIssue == undefined) {
projectGroup.issues.push({ name: issue, contributions: 1 });
}
else {
existingIssue.contributions += 1;
}
};
var result = {};
activities.forEach(function (activity) {
if (result[activity.project] == undefined) {
result[activity.project] = createProjectGroup(activity);
}
else {
var projectGroup = result[activity.project];
projectGroup.activities.push(activity);
if (activity.issue != undefined) {
updateIssue(projectGroup, activity.issue);
}
}
});
var resultArray = $.map(result, function(value, index) { return value; });
resultArray.sort(function (a, b) { return b.activities.length - a.activities.length; });
resultArray.forEach(function (projectGroup) { projectGroup.issues.sort(function (a, b) { return b.contributions - a.contributions; })});
return resultArray;
};
var display = function(userName, projectGroups) {
var maxContributions = Math.max.apply(null, $.map(projectGroups, function (projectGroup, index) { return projectGroup.activities.length; }));
var computeQuartile = function (contributions) {
var quartileSize = maxContributions / 4;
if (maxContributions % 4 != 0) {
quartileSize = Math.ceil(quartileSize);
}
return contributions == maxContributions
? 4
: Math.floor(contributions / quartileSize) + 1;
};
var createHistogram = function(contributions) {
var ul = $("<ul class='histogram'/>");
var quartile = computeQuartile(contributions);
for (var i = 4; i > 0; i--) {
var li = quartile >= i
? $("<li class='quartile-" + i + "' />")
: $("<li class='quartile-0' />");
ul.append(li);
}
return ul;
};
var createHistogramListItem = function(contributions, buildDescriptionSpan) {
var li = $("<li/>");
var histogram = createHistogram(contributions);
li.append(histogram);
li.append(buildDescriptionSpan());
return li;
};
var createIssuesList = function(project, issues) {
var issuesList = $("<ul class='issues toggleable'/>");
for (var issue of issues) {
var issueListItem = createHistogramListItem(issue.contributions, function() {
var bitbucketIssueUrl = "https://bitbucket.org/" + userName + "/" + project + "/issues/" + issue.name;
var url = "<a href='" + bitbucketIssueUrl + "'>#" + issue.name + "</a>";
return "<span class='issue'>" + url + " (" + issue.contributions + ")</span>"; });
issuesList.append(issueListItem);
}
return issuesList;
};
for (var projectGroup of projectGroups) {
var projectListItem = createHistogramListItem(projectGroup.activities.length, function() {
return "<span class='project'>" + projectGroup.project + " (" + projectGroup.activities.length + ")</span>";
});
var issuesList = createIssuesList(projectGroup.project, projectGroup.issues);
projectListItem.append(issuesList);
$("ul.projects").append(projectListItem);
}
};
var loadRssData = function (url, userName) {
$.ajax({
url: url,
}).then(function(data) {
var activities = createActivities(userName, data);
var projectGroups = createProjectGroups(activities);
display(userName, projectGroups);
$("ul.projects > li > ul.histogram").click(function() {
$("ul.toggleable").toggle();
});
});
};
loadRssData(bitbucketRssUrl, bitbucketUserName);
});
</script>
</head>
<body>
<ul class="projects" />
</body>
</html>