summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorJarka Kadlecova <jarka@gitlab.com>2017-05-18 08:07:48 +0200
committerJarka Kadlecova <jarka@gitlab.com>2017-05-30 15:37:27 +0200
commitab8d54b26befb4b70988a514759c7c4d9fd7630d (patch)
tree973f4e83ef76468a00141006fbdc93152e33c028 /app
parent52a3d4372c6e45e4ffb792a9fe7bfca84f3573a3 (diff)
downloadgitlab-ce-ab8d54b26befb4b70988a514759c7c4d9fd7630d.tar.gz
Don’t create comment on JIRA if link already exists
Diffstat (limited to 'app')
-rw-r--r--app/models/project_services/jira_service.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/app/models/project_services/jira_service.rb b/app/models/project_services/jira_service.rb
index fe869623833..25d098b63c0 100644
--- a/app/models/project_services/jira_service.rb
+++ b/app/models/project_services/jira_service.rb
@@ -239,17 +239,26 @@ class JiraService < IssueTrackerService
return unless client_url.present?
jira_request do
- if issue.comments.build.save!(body: message)
- remote_link = issue.remotelink.build
+ remote_link = find_remote_link(issue, remote_link_props[:object][:url])
+ if remote_link
remote_link.save!(remote_link_props)
- result_message = "#{self.class.name} SUCCESS: Successfully posted to #{client_url}."
+ elsif issue.comments.build.save!(body: message)
+ new_remote_link = issue.remotelink.build
+ new_remote_link.save!(remote_link_props)
end
+ result_message = "#{self.class.name} SUCCESS: Successfully posted to #{client_url}."
Rails.logger.info(result_message)
result_message
end
end
+ def find_remote_link(issue, url)
+ links = jira_request { issue.remotelink.all }
+
+ links.find { |link| link.object["url"] == url }
+ end
+
def build_remote_link_props(url:, title:, resolved: false)
status = {
resolved: resolved