2012-10-20 11:02:39 +02:00
|
|
|
/*! Inspired by: http://aboutcode.net/2010/11/11/list-github-projects-using-javascript.html */
|
2012-09-29 15:57:30 +02:00
|
|
|
|
2013-03-02 07:43:52 +01:00
|
|
|
/*jshint forin:true, noarg:true, noempty:true, eqeqeq:true, bitwise:true, strict:false, undef:true, unused:true, curly:true, browser:true, jquery:true, indent:2, maxerr:50 */
|
|
|
|
|
2011-01-16 14:55:32 +01:00
|
|
|
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) {
|
2013-03-02 07:43:09 +01:00
|
|
|
var commits = response.data,
|
|
|
|
list = $('<ul class="rssfeeditems"/>');
|
2011-01-16 14:55:32 +01:00
|
|
|
target.empty().append(list);
|
2013-02-28 11:53:36 +01:00
|
|
|
|
2012-06-14 22:47:39 +02:00
|
|
|
$(commits).each(function(i) {
|
2013-02-28 11:53:36 +01:00
|
|
|
var githubUrl = 'https://github.com/' + username + '/' + repository + '/commit/' + this.sha,
|
|
|
|
shortMessage = cutLines(this.commit.message),
|
2013-03-02 17:55:39 +01:00
|
|
|
commitAuthor = this.author !== null ? this.author.login : this.commit.author.name;
|
2011-01-22 18:05:42 +01:00
|
|
|
|
2013-03-02 08:31:24 +01:00
|
|
|
list.append('<li><a href="' + githubUrl + '">' + shortMessage + '</a> <em>by <strong>' + commitAuthor + '</strong></em></li>');
|
2011-01-16 14:55:32 +01:00
|
|
|
|
2012-11-29 16:02:25 +01:00
|
|
|
if (i === 9) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-01-16 14:55:32 +01:00
|
|
|
});
|
|
|
|
});
|
2011-01-22 18:05:42 +01:00
|
|
|
|
|
|
|
function cutLines(message) {
|
|
|
|
var lineFeed = message.indexOf("\n");
|
2013-02-28 11:53:36 +01:00
|
|
|
|
2011-01-22 18:05:42 +01:00
|
|
|
if (lineFeed > -1) {
|
|
|
|
return message.slice(0, lineFeed);
|
|
|
|
}
|
|
|
|
return message;
|
|
|
|
}
|
2013-02-28 11:53:36 +01:00
|
|
|
};
|