2011-01-16 14:55:32 +01:00
|
|
|
// Inspired by:
|
|
|
|
// http://aboutcode.net/2010/11/11/list-github-projects-using-javascript.html
|
|
|
|
jQuery.fn.listCommits = function(username, repository, branch) {
|
|
|
|
this.html('<span>Querying GitHub for recent commits…</span>');
|
|
|
|
|
|
|
|
var target = this;
|
2012-06-14 22:47:39 +02:00
|
|
|
$.getJSON('https://api.github.com/repos/' + username + '/' + repository + '/commits?sha=' + branch + '&callback=?', function(response) {
|
|
|
|
var commits = response.data;
|
2011-01-16 14:55:32 +01:00
|
|
|
|
|
|
|
var list = $('<ul/>');
|
|
|
|
target.empty().append(list);
|
2012-06-14 22:47:39 +02:00
|
|
|
$(commits).each(function(i) {
|
|
|
|
var githubUrl = 'https://github.com/' + username + '/' + repository + '/commit/' + this.sha;
|
|
|
|
var shortMessage = cutLines(this.commit.message);
|
2011-01-22 18:05:42 +01:00
|
|
|
var author = this.author.login;
|
|
|
|
if (author == '') {
|
|
|
|
author = this.author.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
list.append('<li><a href="' + githubUrl + '">' + shortMessage + '</a> by <strong>' + author + '</strong></li>');
|
2011-01-16 14:55:32 +01:00
|
|
|
|
|
|
|
if (i == 9) return false;
|
|
|
|
});
|
|
|
|
});
|
2011-01-22 18:05:42 +01:00
|
|
|
|
|
|
|
function cutLines(message) {
|
|
|
|
var lineFeed = message.indexOf("\n");
|
|
|
|
if (lineFeed > -1) {
|
|
|
|
return message.slice(0, lineFeed);
|
|
|
|
}
|
|
|
|
return message;
|
|
|
|
}
|
2011-01-16 14:55:32 +01:00
|
|
|
};
|