Commit 0f53ccd1 authored by Justin Ho Tuan Duong's avatar Justin Ho Tuan Duong Committed by Mayra Cabrera

Change Jira service to create comments first

Speculative fix for broken Jira integration.
Tries create comments before trying to create
remote links, which is closer to the previous code.
parent f5c7d8eb
......@@ -280,21 +280,17 @@ class JiraService < IssueTrackerService
return unless client_url.present?
jira_request do
create_issue_link(issue, remote_link_props)
create_issue_comment(issue, message)
remote_link = find_remote_link(issue, remote_link_props[:object][:url])
create_issue_comment(issue, message) unless remote_link
remote_link ||= issue.remotelink.build
remote_link.save!(remote_link_props)
log_info("Successfully posted", client_url: client_url)
"SUCCESS: Successfully posted to #{client_url}."
end
end
def create_issue_link(issue, remote_link_props)
remote_link = find_remote_link(issue, remote_link_props[:object][:url])
remote_link ||= issue.remotelink.build
remote_link.save!(remote_link_props)
end
def create_issue_comment(issue, message)
return unless comment_on_event_enabled
......
......@@ -15,7 +15,7 @@ module Gitlab
unless result.response.is_a?(Net::HTTPSuccess)
Gitlab::ErrorTracking.track_and_raise_exception(
JIRA::HTTPError.new(result.response),
response_body: result.body
response: result.body
)
end
......
......@@ -440,6 +440,27 @@ describe JiraService do
end
end
context 'when Remote Link already exists' do
let(:remote_link) do
double(
'remote link',
object: {
url: "#{Gitlab.config.gitlab.url}/#{project.full_path}/-/commit/#{commit_id}"
}.with_indifferent_access
)
end
it 'does not create comment' do
allow(JIRA::Resource::Remotelink).to receive(:all).and_return([remote_link])
expect(remote_link).to receive(:save!)
@jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
expect(WebMock).not_to have_requested(:post, @comment_url)
end
end
it 'does not send comment or remote links to issues already closed' do
allow_any_instance_of(JIRA::Resource::Issue).to receive(:resolution).and_return(true)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment