mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 14:41:25 +08:00
add GitHub commit onebox
This commit is contained in:
24
lib/oneboxer/github_commit_onebox.rb
Normal file
24
lib/oneboxer/github_commit_onebox.rb
Normal 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
|
Reference in New Issue
Block a user