forked from halfdan/github-commit-history
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github-commit-history.js
50 lines (37 loc) · 1.12 KB
/
github-commit-history.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(function($) {
$.fn.GithubCommitHistory = function(options) {
var defaults = {
username: "halfdan",
repo: "github-commit-history",
branch: "master",
limit: 50,
offset: 0,
gravatar_size: 50
};
var options = $.extend(defaults, options);
return this.each(function() {
var obj = $(this);
var template;
$.get('_commit.html', function(data) {
template = data;
});
jQuery.getJSON("http://github.com/api/v2/json/commits/list/" + options["username"] + "/" + options["repo"] + "/" + options["branch"] + "?callback=?", function(data) {
$.each(data.commits, function(idx, commit) {
// Don't show the first "offset" entries.
if(idx < options["offset"]) {
return true;
}
// Break out of .each of we've reached our limit.
if(idx == options["limit"] + options["offset"]) {
return false;
}
commit = $.extend(commit, options);
// Generate gravatar ID
commit.author.gravatar_id = $.md5(commit.author.email.toLowerCase());
var html = Mustache.to_html(template, commit);
obj.append(html);
});
});
});
};
})(jQuery);