forked from cppcheck-opensource/cppcheck-htdocs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.js
More file actions
52 lines (41 loc) · 1.85 KB
/
github.js
File metadata and controls
52 lines (41 loc) · 1.85 KB
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
51
52
/*! Inspired by: http://aboutcode.net/2010/11/11/list-github-projects-using-javascript.html */
/* jshint browser:true, jquery:true */
// htmlEntities taken from http://css-tricks.com/snippets/javascript/htmlentities-for-javascript/
function htmlEntities(str) {
"use strict";
var ret = String(str)
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """);
return ret;
}
jQuery.fn.listCommits = function(username, repository, branch) {
"use strict";
this.html("<span>Querying GitHub for recent commits…</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;
var shortMessage = htmlEntities(cutLines(this.commit.message));
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>");
}
if (i === 9) {
return false;
}
});
});
function cutLines(message) {
var lineFeed = message.indexOf("\n");
if (lineFeed > -1) {
return message.slice(0, lineFeed);
}
return message;
}
};