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-07-28 10:20:59 +02:00
|
|
|
/* jshint quotmark:true, jquery:true */
|
|
|
|
|
2013-08-29 07:09:11 +02:00
|
|
|
'use strict';
|
|
|
|
|
2013-07-31 13:09:32 +02:00
|
|
|
// htmlEntities taken from http://css-tricks.com/snippets/javascript/htmlentities-for-javascript/
|
|
|
|
function htmlEntities(str) {
|
|
|
|
return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
|
|
}
|
|
|
|
|
2011-01-16 14:55:32 +01:00
|
|
|
jQuery.fn.listCommits = function(username, repository, branch) {
|
2013-03-05 17:51:22 +01:00
|
|
|
this.html('<span>Querying GitHub for recent commits…</span>');
|
2011-01-16 14:55:32 +01:00
|
|
|
|
2013-03-05 17:51:22 +01:00
|
|
|
var target = this;
|
|
|
|
$.getJSON('https://api.github.com/repos/' + username + '/' + repository + '/commits?sha=' + branch + '&callback=?', function(response) {
|
2013-08-17 13:25:50 +02:00
|
|
|
var commits = response.data;
|
|
|
|
var list = $('<ul class="rssfeeditems"/>');
|
|
|
|
|
2013-03-05 17:51:22 +01:00
|
|
|
target.empty().append(list);
|
2013-02-28 11:53:36 +01:00
|
|
|
|
2013-03-05 17:51:22 +01:00
|
|
|
$(commits).each(function(i) {
|
2013-08-17 13:25:50 +02:00
|
|
|
var githubUrl = 'https://github.com/' + username + '/' + repository + '/commit/' + this.sha;
|
|
|
|
var shortMessage = htmlEntities(cutLines(this.commit.message));
|
2011-01-22 18:05:42 +01:00
|
|
|
|
2013-03-16 18:02:32 +01:00
|
|
|
if (this.author !== null) {
|
|
|
|
list.append('<li><a href="' + githubUrl + '">' + shortMessage + '</a><em> by <strong><a class="author" href="' + 'https://github.com/' + this.author.login + '">' + this.author.login + '</a></strong></em></li>');
|
|
|
|
} else {
|
|
|
|
list.append('<li><a href="' + githubUrl + '">' + shortMessage + '</a><em> by <strong>' + this.commit.author.name + '</strong></em></li>');
|
|
|
|
}
|
2011-01-16 14:55:32 +01:00
|
|
|
|
2013-03-05 17:51:22 +01:00
|
|
|
if (i === 9) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2011-01-16 14:55:32 +01:00
|
|
|
});
|
2011-01-22 18:05:42 +01:00
|
|
|
|
2013-03-05 17:51:22 +01:00
|
|
|
function cutLines(message) {
|
2013-07-28 10:20:59 +02:00
|
|
|
var lineFeed = message.indexOf('\n');
|
2013-02-28 11:53:36 +01:00
|
|
|
|
2013-03-05 17:51:22 +01:00
|
|
|
if (lineFeed > -1) {
|
|
|
|
return message.slice(0, lineFeed);
|
|
|
|
}
|
|
|
|
return message;
|
2011-01-22 18:05:42 +01:00
|
|
|
}
|
2013-02-28 11:53:36 +01:00
|
|
|
};
|