From 219be7727d4d00fcfaa63ea756f4adce7411978c Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 30 Sep 2012 19:04:27 -0500 Subject: add github activity to the main page --- root/static/github_activity.js | 74 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 root/static/github_activity.js (limited to 'root/static/github_activity.js') diff --git a/root/static/github_activity.js b/root/static/github_activity.js new file mode 100644 index 0000000..a20dd12 --- /dev/null +++ b/root/static/github_activity.js @@ -0,0 +1,74 @@ +/** + * Github activity feed. + * + * Graeme Sutherland, July 2012. + * + * Uses .json activity from github to show public commits. + * Requires jQuery and underscore.js + * + */ + +var GithubActivity = (function($, _) { + + var + self = {}, + gh = 'http://github.com/', + default_template = '
  • \ + <% if (type == "PushEvent") { %> \ + <%= actor %> \ + pushed \ + to \ + <%= repository.name %> on \ + <% print(created_at.substring(0, 10)); %>. \ + \ + <% } else if (type == "GistEvent") { %> \ + <%= actor %> \ + <%= payload.action %>d gist: \ + <%= payload.desc %>.\ + <% } else if (type == "CreateEvent") { %> \ + <%= actor %> \ + created <%= payload.ref_type %> \ + <%= payload.ref %> in \ + <%= repository.name %> on \ + <% print(created_at.substring(0, 10)); %>. \ + <% } else if (type == "PullRequestEvent") { %> \ + <%= actor %> \ + <%= payload.action %> pull request \ + \ + #<%= payload.number %>: <%= payload.pull_request.title %> \ + on <% print(created_at.substring(0, 10)); %>. \ + <% } else if (type == "IssueCommentEvent") { %> \ + <%= actor %> \ + commented on issue \ + #<% print(url.replace(/.*\\/issues\\/(\\d+)#.*/, "$1")); %> \ + in <%= repository.name %> \ + on <% print(created_at.substring(0, 10)); %>. \ + <% } else { %> \ + Unknown event type <% type %>. \ + <% } %>\ +
  • '; + + /** + * Fill in activity into selector from public events for username, + * with optional template selector tmpl_selector. + */ + self.show_activity = function (username, selector, tmpl_selector) { + var + url = 'https://github.com/' + username + '.json?callback=?', + template = $(tmpl_selector).html() || default_template, + compiled = _.template(template); + + $.getJSON(url, {}, function (data) { + $.each(data.slice(0, 6), function(index, commit) { + $(selector).append(compiled(commit)); + }); + }); + }; + + return self; + +}(jQuery, _)); -- cgit v1.2.3-54-g00ecf