mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
Add onebox for GitHub pull requests
This commit is contained in:
parent
c2821bee91
commit
d741798d9c
3 changed files with 82 additions and 0 deletions
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
|
39
lib/oneboxer/templates/github_pullrequest_onebox.hbrs
Normal file
39
lib/oneboxer/templates/github_pullrequest_onebox.hbrs
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<div class="onebox-result">
|
||||||
|
{{#host}}
|
||||||
|
<div class="source">
|
||||||
|
<div class="info">
|
||||||
|
<a href="{{html_url}}" class="track-link" target="_blank">
|
||||||
|
{{#favicon}}
|
||||||
|
<img class="favicon" src="{{favicon}}">
|
||||||
|
{{/favicon}}
|
||||||
|
{{host}}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/host}}
|
||||||
|
|
||||||
|
<div class="onebox-result-body">
|
||||||
|
{{#user.avatar_url}}
|
||||||
|
<a href="{{user.html_url}}" target="_blank">
|
||||||
|
<img alt="{{user.login}}" src="{{user.avatar_url}}">
|
||||||
|
</a>
|
||||||
|
{{/user.avatar_url}}
|
||||||
|
|
||||||
|
<h4>
|
||||||
|
<a href="{{html_url}}" target="_blank">{{title}}</a>
|
||||||
|
</h4>
|
||||||
|
|
||||||
|
<div class="date">
|
||||||
|
by <a href="{{user.html_url}}" target="_blank">{{user.login}}</a>
|
||||||
|
on <a href="{{html_url}}" target="_blank">{{created_at}}</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="github-commit-stats">
|
||||||
|
<strong>{{commits}} commits</strong>
|
||||||
|
changed <strong>{{changed_files}} files</strong>
|
||||||
|
with <strong>{{additions}} additions</strong>
|
||||||
|
and <strong>{{deletions}} deletions</strong>.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
</div>
|
17
spec/components/oneboxer/github_pullrequest_onebox_spec.rb
Normal file
17
spec/components/oneboxer/github_pullrequest_onebox_spec.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
require 'oneboxer'
|
||||||
|
require 'oneboxer/github_pullrequest_onebox'
|
||||||
|
|
||||||
|
describe Oneboxer::GithubPullrequestOnebox do
|
||||||
|
describe '#translate_url' do
|
||||||
|
it 'returns the api url for the given pull request' do
|
||||||
|
onebox = described_class.new(
|
||||||
|
'https://github.com/discourse/discourse/pull/988'
|
||||||
|
)
|
||||||
|
expect(onebox.translate_url).to eq(
|
||||||
|
'https://api.github.com/repos/discourse/discourse/pulls/988'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue