Ensure `JIRA::Resource::Issue` responds to `resolution` before calling it

This commit is contained in:
Mehdi Lahmam 2017-08-01 21:19:54 +02:00
parent 56046ca8da
commit 03d199fb10
2 changed files with 15 additions and 2 deletions

View File

@ -104,7 +104,7 @@ class JiraService < IssueTrackerService
def close_issue(entity, external_issue)
issue = jira_request { client.Issue.find(external_issue.iid) }
return if issue.nil? || issue.resolution.present? || !jira_issue_transition_id.present?
return if issue.nil? || has_resolution?(issue) || !jira_issue_transition_id.present?
commit_id = if entity.is_a?(Commit)
entity.id
@ -118,7 +118,7 @@ class JiraService < IssueTrackerService
# may or may not be allowed. Refresh the issue after transition and check
# if it is closed, so we don't have one comment for every commit.
issue = jira_request { client.Issue.find(issue.key) } if transition_issue(issue)
add_issue_solved_comment(issue, commit_id, commit_url) if issue.resolution
add_issue_solved_comment(issue, commit_id, commit_url) if has_resolution?(issue)
end
def create_cross_reference_note(mentioned, noteable, author)
@ -216,6 +216,10 @@ class JiraService < IssueTrackerService
end
end
def has_resolution?(issue)
issue.respond_to?(:resolution) && issue.resolution.present?
end
def comment_exists?(issue, message)
comments = jira_request { issue.comments }

View File

@ -153,6 +153,15 @@ describe JiraService do
expect(WebMock).not_to have_requested(:post, @remote_link_url)
end
it "does not send comment or remote links to issues with unknown resolution" do
allow_any_instance_of(JIRA::Resource::Issue).to receive(:respond_to?).with(:resolution).and_return(false)
@jira_service.close_issue(merge_request, ExternalIssue.new("JIRA-123", project))
expect(WebMock).not_to have_requested(:post, @comment_url)
expect(WebMock).not_to have_requested(:post, @remote_link_url)
end
it "references the GitLab commit/merge request" do
stub_config_setting(base_url: custom_base_url)