summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2016-11-17 18:46:31 -0200
committerFelipe Artur <felipefac@gmail.com>2016-11-21 12:09:41 -0200
commit9c740133a3bb4e992ccd7e3801402e4eab537e29 (patch)
tree4ab0a8a8a98f6d5ff914c1946c8a7133d12691d9 /app
parent671c6d7d577d6b872bee7634c4eaf6b4da16919f (diff)
downloadgitlab-ce-9c740133a3bb4e992ccd7e3801402e4eab537e29.tar.gz
Allow JIRA references for project snippetsissue_24303
Diffstat (limited to 'app')
-rw-r--r--app/models/concerns/mentionable.rb2
-rw-r--r--app/models/project_services/jira_service.rb30
-rw-r--r--app/models/snippet.rb1
3 files changed, 18 insertions, 15 deletions
diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb
index eb2ff0428f6..8ab0401d288 100644
--- a/app/models/concerns/mentionable.rb
+++ b/app/models/concerns/mentionable.rb
@@ -1,6 +1,6 @@
# == Mentionable concern
#
-# Contains functionality related to objects that can mention Users, Issues, MergeRequests, or Commits by
+# Contains functionality related to objects that can mention Users, Issues, MergeRequests, Commits or Snippets by
# GFM references.
#
# Used by Issue, Note, MergeRequest, and Commit.
diff --git a/app/models/project_services/jira_service.rb b/app/models/project_services/jira_service.rb
index 2caf6179ef8..aeded715893 100644
--- a/app/models/project_services/jira_service.rb
+++ b/app/models/project_services/jira_service.rb
@@ -128,15 +128,9 @@ class JiraService < IssueTrackerService
return unless jira_issue.present?
- project = self.project
- noteable_name = noteable.model_name.singular
- noteable_id = if noteable.is_a?(Commit)
- noteable.id
- else
- noteable.iid
- end
-
- entity_url = build_entity_url(noteable_name.to_sym, noteable_id)
+ noteable_id = noteable.respond_to?(:iid) ? noteable.iid : noteable.id
+ noteable_type = noteable_name(noteable)
+ entity_url = build_entity_url(noteable_type, noteable_id)
data = {
user: {
@@ -144,11 +138,11 @@ class JiraService < IssueTrackerService
url: resource_url(user_path(author)),
},
project: {
- name: project.path_with_namespace,
- url: resource_url(namespace_project_path(project.namespace, project))
+ name: self.project.path_with_namespace,
+ url: resource_url(namespace_project_path(project.namespace, self.project))
},
entity: {
- name: noteable_name.humanize.downcase,
+ name: noteable_type.humanize.downcase,
url: entity_url,
title: noteable.title
}
@@ -285,18 +279,26 @@ class JiraService < IssueTrackerService
"#{Settings.gitlab.base_url.chomp("/")}#{resource}"
end
- def build_entity_url(entity_name, entity_id)
+ def build_entity_url(noteable_type, entity_id)
polymorphic_url(
[
self.project.namespace.becomes(Namespace),
self.project,
- entity_name
+ noteable_type.to_sym
],
id: entity_id,
host: Settings.gitlab.base_url
)
end
+ def noteable_name(noteable)
+ name = noteable.model_name.singular
+
+ # ProjectSnippet inherits from Snippet class so it causes
+ # routing error building the URL.
+ name == "project_snippet" ? "snippet" : name
+ end
+
# Handle errors when doing JIRA API calls
def jira_request
yield
diff --git a/app/models/snippet.rb b/app/models/snippet.rb
index 2373b445009..8ff4e7ae718 100644
--- a/app/models/snippet.rb
+++ b/app/models/snippet.rb
@@ -6,6 +6,7 @@ class Snippet < ActiveRecord::Base
include Referable
include Sortable
include Awardable
+ include Mentionable
cache_markdown_field :title, pipeline: :single_line
cache_markdown_field :content