cppcheck/htdocs/site/js/github.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

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
jQuery.fn.listCommits = function(username, repository, branch) {
this.html('<span>Querying GitHub for recent commits&hellip;</span>');
var target = this;
$.getJSON('https://api.github.com/repos/' + username + '/' + repository + '/commits?sha=' + branch + '&callback=?', function(response) {
var commits = response.data;
var list = $('<ul class="rssfeeditems"/>');
target.empty().append(list);
$(commits).each(function(i) {
var githubUrl = 'https://github.com/' + username + '/' + repository + '/commit/' + this.sha,
shortMessage = cutLines(this.commit.message),
commitAuthor;
2013-02-23 05:42:09 +01:00
if (this.author !== null) {
commitAuthor = this.author.login;
2011-01-22 18:05:42 +01:00
}
if (commitAuthor) {
list.append('<li><a href="' + githubUrl + '">' + shortMessage + '</a> <em>by <strong>' + commitAuthor + '</strong></em></li>');
} else {
list.append('<li><a href="' + githubUrl + '">' + shortMessage + '</a></li>');
}
2012-11-29 16:02:25 +01:00
if (i === 9) {
return false;
}
});
});
2011-01-22 18:05:42 +01:00
function cutLines(message) {
var lineFeed = message.indexOf("\n");
2011-01-22 18:05:42 +01:00
if (lineFeed > -1) {
return message.slice(0, lineFeed);
}
return message;
}
};