lib/onebox/engine/github_commit_onebox.rb in onebox-1.1.0 vs lib/onebox/engine/github_commit_onebox.rb in onebox-1.2.0
- old
+ new
@@ -1,9 +1,10 @@
module Onebox
module Engine
class GithubCommitOnebox
include Engine
+ include LayoutSupport
include JSON
matches do
http
maybe("www.")
@@ -12,32 +13,24 @@
anything
with("/commit/")
end
def url
- "https://api.github.com/repos/#{match[:owner]}/#{match[:repo]}/commits/#{match[:number]}"
+ "https://api.github.com/repos/#{match[:owner]}/#{match[:repository]}/commits/#{match[:sha]}"
end
private
def match
- @url.match(/github\.com\/(?<owner>[^\/]+)\/(?<repo>[^\/]+)\/commit\/(?<number>[^\/]+)/)
+ @match ||= @url.match(%{github\.com/(?<owner>[^/]+)/(?<repository>[^/]+)/commit/(?<sha>[^/]+)})
end
def data
- {
- url: @url,
- owner: match[:owner],
- repo: match[:repo],
- sha: raw["sha"],
- gravatar: raw["author"]["avatar_url"],
- message: raw["commit"]["message"],
- author: raw["author"]["login"],
- time_date: raw["commit"]["committer"]["date"],
- files_changed: raw["files"].length,
- additions: raw["stats"]["additions"],
- deletions: raw["stats"]["deletions"]
- }
+ result = raw.clone
+ result['link'] = link
+ result['title'] = result['commit']['message']
+ result['commit_date'] = Time.parse(result['commit']['author']['date']).strftime("%I:%M%p - %d %b %y")
+ result
end
end
end
end