Add onebox for GitHub pull requests

This commit is contained in:
Chris Hunt
2013-06-08 10:27:36 -07:00
parent c2821bee91
commit d741798d9c
3 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1,26 @@
require_dependency 'oneboxer/handlebars_onebox'
module Oneboxer
class GithubPullrequestOnebox < HandlebarsOnebox
matcher /^https?:\/\/(?:www\.)?github\.com\/[^\/]+\/[^\/]+\/pull\/.+/
favicon 'github.png'
def translate_url
@url.match(
/github\.com\/(?<owner>[^\/]+)\/(?<repo>[^\/]+)\/pull\/(?<number>[^\/]+)/mi
) do |match|
"https://api.github.com/repos/#{match[:owner]}/#{match[:repo]}/pulls/#{match[:number]}"
end
end
def parse(data)
result = JSON.parse(data)
result['created_at'] =
Time.parse(result['created_at']).strftime("%I:%M%p - %d %b %y")
result
end
end
end