BigW Consortium Gitlab

Commit 03d199fb by Mehdi Lahmam

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

parent 56046ca8
...@@ -104,7 +104,7 @@ class JiraService < IssueTrackerService ...@@ -104,7 +104,7 @@ class JiraService < IssueTrackerService
def close_issue(entity, external_issue) def close_issue(entity, external_issue)
issue = jira_request { client.Issue.find(external_issue.iid) } 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) commit_id = if entity.is_a?(Commit)
entity.id entity.id
...@@ -118,7 +118,7 @@ class JiraService < IssueTrackerService ...@@ -118,7 +118,7 @@ class JiraService < IssueTrackerService
# may or may not be allowed. Refresh the issue after transition and check # 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. # 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) 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 end
def create_cross_reference_note(mentioned, noteable, author) def create_cross_reference_note(mentioned, noteable, author)
...@@ -216,6 +216,10 @@ class JiraService < IssueTrackerService ...@@ -216,6 +216,10 @@ class JiraService < IssueTrackerService
end end
end end
def has_resolution?(issue)
issue.respond_to?(:resolution) && issue.resolution.present?
end
def comment_exists?(issue, message) def comment_exists?(issue, message)
comments = jira_request { issue.comments } comments = jira_request { issue.comments }
......
...@@ -153,6 +153,15 @@ describe JiraService do ...@@ -153,6 +153,15 @@ describe JiraService do
expect(WebMock).not_to have_requested(:post, @remote_link_url) expect(WebMock).not_to have_requested(:post, @remote_link_url)
end 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 it "references the GitLab commit/merge request" do
stub_config_setting(base_url: custom_base_url) stub_config_setting(base_url: custom_base_url)
......
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