add GitHub commit onebox

This commit is contained in:
Régis Hanol
2013-04-03 03:36:38 +02:00
parent ee76f1926d
commit cf3eb98321
4 changed files with 373 additions and 0 deletions

View File

@ -0,0 +1,24 @@
require_dependency 'oneboxer/handlebars_onebox'
module Oneboxer
class GithubCommitOnebox < HandlebarsOnebox
matcher /^https?:\/\/(?:www\.)?github\.com\/[^\/]+\/[^\/]+\/commit\/.+/
favicon 'github.png'
def translate_url
m = @url.match(/github\.com\/(?<owner>[^\/]+)\/(?<repo>[^\/]+)\/commit\/(?<sha>[^\/]+)/mi)
return "https://api.github.com/repos/#{m[:owner]}/#{m[:repo]}/commits/#{m[:sha]}" if m.present?
@url
end
def parse(data)
result = JSON.parse(data)
result['commit_date'] = Time.parse(result['commit']['author']['date']).strftime("%I:%M%p - %d %b %y")
result
end
end
end