New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Backlog Webhook #58
Changes from 2 commits
b2a7a6a
1d16d17
5cfde74
e317175
d288e1f
3088a6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
%dl | ||
%dt Usage | ||
%dd | ||
%p | ||
You can add webhook URL to your team in backlog. | ||
%br | ||
See <a href='http://www.backlog.jp/help/adminsguide/webhook-setting/userguide2493.html' target='_blank'><i class='fa fa-external-link'></i>Webhook | Backlog</a> for more details. | ||
%p Please append <code>space_id</code> parameter as below. | ||
%pre {{endpoint}}?space_id=<code>hogehoge</code> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module Idobata::Hook | ||
class Backlog < Base | ||
module Helper | ||
def type_label | ||
case payload.type | ||
when 1 | ||
label = 'created' | ||
when 2 | ||
label = 'updated' | ||
when 3 | ||
label = 'commented' | ||
when 4 | ||
label = 'issue deleted' | ||
when 17 | ||
label = 'noticed' | ||
when 14 | ||
label = 'multiple issues updated' | ||
end | ||
label | ||
end | ||
|
||
def backlog_url_base | ||
"https://#{space_id}.backlog.jp/view/#{payload.project.projectKey}" if space_id | ||
end | ||
|
||
def backlog_urls | ||
urls = [] | ||
if backlog_url_base | ||
if payload.content.key_id | ||
url = "#{backlog_url_base}-#{payload.content.key_id}" | ||
url += "#comment-#{payload.content.comment.id}" if payload.content.comment && payload.content.comment.id | ||
urls << url | ||
else | ||
payload.content.link.each do |link| | ||
urls << "#{backlog_url_base}-#{link.key_id}" if link.key_id | ||
end | ||
end | ||
end | ||
urls | ||
end | ||
|
||
def md(source) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this necessary? It seems not used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The parameter called Is it not such a thing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yep, you're right 😃 I think the To be honest, I couldn't make out what you were getting at. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I'm sorry. It was misunderstanding.:dizzy_face: |
||
HTML::Pipeline::MarkdownFilter.new(source, gfm: true).call.to_s.html_safe | ||
end | ||
|
||
def hbr(source) | ||
html_escape(source).gsub(/\r\n|\r|\n/, "<br />").html_safe | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Idobata::Hook | ||
class Backlog < Base | ||
screen_name 'backlog' | ||
icon_url hook_image_url('icon.png') | ||
template_name { "#{type}.html.haml" } | ||
|
||
helper Helper | ||
|
||
private | ||
|
||
def type | ||
case payload.type | ||
when 1, 2, 3, 4, 14, 17 | ||
'issue' | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you like to return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, would you please skip processing when receiving unsupported event? Like this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes.Thank you! |
||
end | ||
|
||
def space_id | ||
params[:space_id] || nil | ||
end | ||
|
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
%p | ||
%b= payload.content.summary | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about making this a link to the issue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will do so! |
||
#{type_label} by #{payload.createdUser.name}. | ||
|
||
- backlog_urls.each do |url| | ||
%p | ||
%a{href: url}= url | ||
|
||
- if payload.type == 1 | ||
%p=hbr payload.content.description | ||
|
||
- if payload.content.comment | ||
%p=hbr payload.content.comment.content |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
describe Idobata::Hook::Backlog, type: :hook do | ||
let(:payload) { fixture_payload("backlog/#{payload_type}.json") } | ||
|
||
describe '#process_payload' do | ||
subject { hook.process_payload } | ||
|
||
context 'on issue create without space_id' do | ||
let(:payload_type) { 'issue_create' } | ||
|
||
before do | ||
post payload, {'Content-Type' => 'application/json'} | ||
end | ||
|
||
its([:source]) { should eq(<<-HTML.strip_heredoc) } | ||
<p> | ||
<b>test issue</b> | ||
created by ozamasa. | ||
<p>test description</p> | ||
</p> | ||
HTML | ||
|
||
its([:format]) { should eq(:html) } | ||
end | ||
|
||
context 'on issue create' do | ||
let(:payload_type) { 'issue_create' } | ||
|
||
before do | ||
post payload, {'Content-Type' => 'application/json'}, {space_id: 'test'} | ||
end | ||
|
||
its([:source]) { should eq(<<-HTML.strip_heredoc) } | ||
<p> | ||
<b>test issue</b> | ||
created by ozamasa. | ||
<p> | ||
<a href='https://test.backlog.jp/view/TEST-100'>https://test.backlog.jp/view/TEST-100</a> | ||
</p> | ||
<p>test description</p> | ||
</p> | ||
HTML | ||
|
||
its([:format]) { should eq(:html) } | ||
end | ||
|
||
context 'on issue update' do | ||
let(:payload_type) { 'issue_update' } | ||
|
||
before do | ||
post payload, {'Content-Type' => 'application/json'}, {space_id: 'test'} | ||
end | ||
|
||
its([:source]) { should eq(<<-HTML.strip_heredoc) } | ||
<p> | ||
<b>test issue</b> | ||
updated by ozamasa. | ||
<p> | ||
<a href='https://test.backlog.jp/view/TEST-100#comment-200'>https://test.backlog.jp/view/TEST-100#comment-200</a> | ||
</p> | ||
<p></p> | ||
</p> | ||
HTML | ||
|
||
its([:format]) { should eq(:html) } | ||
end | ||
|
||
context 'on issue comment' do | ||
let(:payload_type) { 'issue_comment' } | ||
|
||
before do | ||
post payload, {'Content-Type' => 'application/json'}, {space_id: 'test'} | ||
end | ||
|
||
its([:source]) { should eq(<<-HTML.strip_heredoc) } | ||
<p> | ||
<b>test issue</b> | ||
commented by ozamasa. | ||
<p> | ||
<a href='https://test.backlog.jp/view/TEST-100#comment-200'>https://test.backlog.jp/view/TEST-100#comment-200</a> | ||
</p> | ||
<p>test comment</p> | ||
</p> | ||
HTML | ||
|
||
its([:format]) { should eq(:html) } | ||
end | ||
|
||
context 'on issue comment' do | ||
let(:payload_type) { 'issue_comment' } | ||
|
||
before do | ||
post payload, {'Content-Type' => 'application/json'}, {space_id: 'test'} | ||
end | ||
|
||
its([:source]) { should eq(<<-HTML.strip_heredoc) } | ||
<p> | ||
<b>test issue</b> | ||
commented by ozamasa. | ||
<p> | ||
<a href='https://test.backlog.jp/view/TEST-100#comment-200'>https://test.backlog.jp/view/TEST-100#comment-200</a> | ||
</p> | ||
<p>test comment</p> | ||
</p> | ||
HTML | ||
|
||
its([:format]) { should eq(:html) } | ||
end | ||
|
||
context 'on issue delete' do | ||
let(:payload_type) { 'issue_delete' } | ||
|
||
before do | ||
post payload, {'Content-Type' => 'application/json'}, {space_id: 'test'} | ||
end | ||
|
||
its([:source]) { should eq(<<-HTML.strip_heredoc) } | ||
<p> | ||
<b></b> | ||
issue deleted by ozamasa. | ||
<p> | ||
<a href='https://test.backlog.jp/view/TEST-100'>https://test.backlog.jp/view/TEST-100</a> | ||
</p> | ||
</p> | ||
HTML | ||
|
||
its([:format]) { should eq(:html) } | ||
end | ||
|
||
context 'on issue multipul update' do | ||
let(:payload_type) { 'issue_multipul_update' } | ||
|
||
before do | ||
post payload, {'Content-Type' => 'application/json'}, {space_id: 'test'} | ||
end | ||
|
||
its([:source]) { should eq(<<-HTML.strip_heredoc) } | ||
<p> | ||
<b></b> | ||
multiple issues updated by ozamasa. | ||
<p> | ||
<a href='https://test.backlog.jp/view/TEST-100'>https://test.backlog.jp/view/TEST-100</a> | ||
</p> | ||
<p> | ||
<a href='https://test.backlog.jp/view/TEST-101'>https://test.backlog.jp/view/TEST-101</a> | ||
</p> | ||
</p> | ||
HTML | ||
|
||
its([:format]) { should eq(:html) } | ||
end | ||
|
||
context 'on issue notice' do | ||
let(:payload_type) { 'issue_notice' } | ||
|
||
before do | ||
post payload, {'Content-Type' => 'application/json'}, {space_id: 'test'} | ||
end | ||
|
||
its([:source]) { should eq(<<-HTML.strip_heredoc) } | ||
<p> | ||
<b>test issue</b> | ||
noticed by ozamasa. | ||
<p> | ||
<a href='https://test.backlog.jp/view/TEST-100#comment-200'>https://test.backlog.jp/view/TEST-100#comment-200</a> | ||
</p> | ||
<p>test comment</p> | ||
</p> | ||
HTML | ||
|
||
its([:format]) { should eq(:html) } | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"created":"2015-11-24T00:00:00Z", | ||
"project":{ | ||
"archived":false, | ||
"projectKey":"TEST", | ||
"name":"TestProject", | ||
"chartEnabled":false, | ||
"id":100, | ||
"subtaskingEnabled":false | ||
}, | ||
"id":10, | ||
"type":3, | ||
"content":{ | ||
"summary":"test issue", | ||
"key_id":100, | ||
"description":"test description", | ||
"comment":{ | ||
"id":200, | ||
"content":"test comment" | ||
}, | ||
"id":100 | ||
}, | ||
"notifications":[], | ||
"createdUser":{ | ||
"name":"ozamasa", | ||
"mailAddress":null, | ||
"id":6336, | ||
"roleType":1, | ||
"lang":"ja", | ||
"userId":null | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"created":"2015-11-24T00:00:00Z", | ||
"project":{ | ||
"archived":false, | ||
"projectKey":"TEST", | ||
"name":"TestProject", | ||
"chartEnabled":false, | ||
"id":100, | ||
"subtaskingEnabled":false | ||
}, | ||
"id":10, | ||
"type":1, | ||
"content":{ | ||
"summary":"test issue", | ||
"key_id":100, | ||
"description":"test description", | ||
"id":100 | ||
}, | ||
"notifications":[], | ||
"createdUser":{ | ||
"name":"ozamasa", | ||
"mailAddress":null, | ||
"id":6336, | ||
"roleType":1, | ||
"lang":"ja", | ||
"userId":null | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"created":"2015-11-24T00:00:00Z", | ||
"project":{ | ||
"archived":false, | ||
"projectKey":"TEST", | ||
"name":"TestProject", | ||
"chartEnabled":false, | ||
"id":100, | ||
"subtaskingEnabled":false | ||
}, | ||
"id":10, | ||
"type":4, | ||
"content":{ | ||
"key_id":100, | ||
"id":100 | ||
}, | ||
"notifications":[], | ||
"createdUser":{ | ||
"name":"ozamasa", | ||
"mailAddress":null, | ||
"id":6336, | ||
"roleType":1, | ||
"lang":"ja", | ||
"userId":null | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use
try
here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I'll fix it!