mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 09:57:25 +08:00
Add onebox for GitHub pull requests
This commit is contained in:
26
lib/oneboxer/github_pullrequest_onebox.rb
Normal file
26
lib/oneboxer/github_pullrequest_onebox.rb
Normal 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
|
Reference in New Issue
Block a user