// Loop over each retrieved GitHub event and process.
$.each(data, function(i, githubEvent) {
// The icon font to be displayed with the event.
var octicon = "";
// The hyper link to be applied to the displayed event.
var link = "";
// The text to be displayed with the event.
var text = "";
// Only show 10 events. Not all types of GitHub events are implemented here.
// for the full list, see https://developer.github.com/v3/activity/events/types/
if(count < 10) {
if(githubEvent.type == 'CommitCommentEvent') {
octicon = "octicon-comment";
link = githubEvent.payload.comment.html_url;
text = "Commented on " + githubEvent.repo.name + "/commit/" + githubEvent.payload.comment.commit_id;
} else if(githubEvent.type == 'CreateEvent') {
octicon = "octicon-repo-create";
link = "http://github.com/" + githubEvent.repo.name;
text = "Created repository " + githubEvent.repo.name;
} else if(githubEvent.type == 'ForkEvent') {
octicon = "octicon-repo-forked";
link = githubEvent.payload.forkee.html_url;
text = "Forked repository " + githubEvent.repo.name;
} else if(githubEvent.type == 'IssuesEvent') {
octicon = "octicon-issue-" + githubEvent.payload.action;
link = githubEvent.payload.issue.html_url;
text = githubEvent.payload.action.capitalize() + " issue " + githubEvent.repo.name
+ "#" + githubEvent.payload.issue.number;
} else if(githubEvent.type == 'IssueCommentEvent') {
octicon = "octicon-comment-discussion";
link = githubEvent.payload.issue.html_url;
text = "Commented on " + (githubEvent.payload.issue.pull_request.url != null ? "pull request" : "issue") +
" " + githubEvent.repo.name + "#" + githubEvent.payload.issue.number;
} else if(githubEvent.type == 'PullRequestEvent') {
octicon = 'octicon-git-pull-request';
link = githubEvent.payload.pull_request.html_url;
text = githubEvent.payload.action.capitalize() + " pull request " + githubEvent.repo.name
+ "#" + githubEvent.payload.number;
} else if(githubEvent.type == 'PullRequestReviewCommentEvent') {
octicon = "octicon-comment";
link = githubEvent.payload.comment.html_url;
text = "Commented on pull request " + githubEvent.repo.name + "#"
+ extractPullRequestNumber(githubEvent.payload.comment.pull_request_url);
} else if(githubEvent.type == 'PushEvent' && !(githubEvent.repo.name == "jdpgrailsdev/blog")) {
octicon = "octicon-git-commit";
link = "http://github.com/" + githubEvent.repo.name + "/commit/" + githubEvent.payload.head;
text = "Pushed to " + normalizeBranch(githubEvent.payload.ref) + " at " + githubEvent.repo.name;
}
// If the event is one of the supported types, add a new line item to the HTML panel.
if(text) {
var eventDateHtml = createEventDateHtml(githubEvent.created_at);
activityList.append("<li id=\"" + githubEvent.id + "\" class=\"list-group-item\"><div><span class=\"octicon " +
octicon + "\"></span><a href=\"" + link + "\" target=\"_blank\"> " + text + "</a></div>" + eventDateHtml + "</li>");
count++;
}
}
});