diff options
author | Rémy Coutable <remy@rymai.me> | 2017-08-04 09:41:50 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-08-04 09:41:50 +0000 |
commit | 40bdbfb096d1ea4dac9e5ce33042c3ab482a4062 (patch) | |
tree | 33a86a0cc53e15af564600749aa344b510ed0ff1 | |
parent | e92966083acf114ae9b738ec60458796a3daad5c (diff) | |
parent | 03d199fb10bd03c6d6602b23e5f5454dd956e945 (diff) | |
download | gitlab-ce-40bdbfb096d1ea4dac9e5ce33042c3ab482a4062.tar.gz |
Merge branch 'fix-jira-integration' into 'master'
Ensure `JIRA::Resource::Issue` responds to `resolution` before calling it
See merge request !13240
-rw-r--r-- | app/models/project_services/jira_service.rb | 8 | ||||
-rw-r--r-- | spec/models/project_services/jira_service_spec.rb | 9 |
2 files changed, 15 insertions, 2 deletions
diff --git a/app/models/project_services/jira_service.rb b/app/models/project_services/jira_service.rb index c2414885368..9ee3a533c1e 100644 --- a/app/models/project_services/jira_service.rb +++ b/app/models/project_services/jira_service.rb @@ -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 } diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb index 204a00778a7..63bf131cfc5 100644 --- a/spec/models/project_services/jira_service_spec.rb +++ b/spec/models/project_services/jira_service_spec.rb @@ -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) |