/*! Inspired by: http://aboutcode.net/2010/11/11/list-github-projects-using-javascript.html */
jQuery.fn.listCommits = function(username, repository, branch) {
this.html('Querying GitHub for recent commits…');
var target = this;
$.getJSON('https://api.github.com/repos/' + username + '/' + repository + '/commits?sha=' + branch + '&callback=?', function(response) {
var commits = response.data,
list = $('
');
target.empty().append(list);
$(commits).each(function(i) {
var githubUrl = 'https://github.com/' + username + '/' + repository + '/commit/' + this.sha,
shortMessage = cutLines(this.commit.message);
if (this.author !== null) {
list.append('' + shortMessage + ' by ' + this.author.login + '');
} else {
list.append('' + shortMessage + ' by ' + this.commit.author.name + '');
}
if (i === 9) {
return false;
}
});
});
function cutLines(message) {
var lineFeed = message.indexOf("\n");
if (lineFeed > -1) {
return message.slice(0, lineFeed);
}
return message;
}
};