diff --git a/lib/gitlab/markdown/commit_range_reference_filter.rb b/lib/gitlab/markdown/commit_range_reference_filter.rb
index 61591a9914b..a9f1ee9c161 100644
--- a/lib/gitlab/markdown/commit_range_reference_filter.rb
+++ b/lib/gitlab/markdown/commit_range_reference_filter.rb
@@ -57,10 +57,11 @@ module Gitlab
title = range.reference_title
klass = reference_class(:commit_range)
+ data = data_attribute(project.id)
project_ref += '@' if project_ref
- %(#{project_ref}#{range})
else
diff --git a/lib/gitlab/markdown/commit_reference_filter.rb b/lib/gitlab/markdown/commit_reference_filter.rb
index f6932e76e70..eacdf8a6d37 100644
--- a/lib/gitlab/markdown/commit_reference_filter.rb
+++ b/lib/gitlab/markdown/commit_reference_filter.rb
@@ -47,10 +47,11 @@ module Gitlab
title = escape_once(commit.link_title)
klass = reference_class(:commit)
+ data = data_attribute(project.id)
project_ref += '@' if project_ref
- %(#{project_ref}#{commit.short_id})
else
diff --git a/lib/gitlab/markdown/issue_reference_filter.rb b/lib/gitlab/markdown/issue_reference_filter.rb
index dea04761ead..ab6f6bc1cf7 100644
--- a/lib/gitlab/markdown/issue_reference_filter.rb
+++ b/lib/gitlab/markdown/issue_reference_filter.rb
@@ -49,8 +49,9 @@ module Gitlab
title = escape_once("Issue: #{issue.title}")
klass = reference_class(:issue)
+ data = data_attribute(project.id)
- %(#{match})
else
diff --git a/lib/gitlab/markdown/label_reference_filter.rb b/lib/gitlab/markdown/label_reference_filter.rb
index e022ca69c91..2186f36f854 100644
--- a/lib/gitlab/markdown/label_reference_filter.rb
+++ b/lib/gitlab/markdown/label_reference_filter.rb
@@ -43,8 +43,9 @@ module Gitlab
url = url_for_label(project, label)
klass = reference_class(:label)
+ data = data_attribute(project.id)
- %(#{render_colored_label(label)})
else
match
diff --git a/lib/gitlab/markdown/merge_request_reference_filter.rb b/lib/gitlab/markdown/merge_request_reference_filter.rb
index 80779819485..884f60f9d53 100644
--- a/lib/gitlab/markdown/merge_request_reference_filter.rb
+++ b/lib/gitlab/markdown/merge_request_reference_filter.rb
@@ -47,10 +47,11 @@ module Gitlab
title = escape_once("Merge Request: #{merge_request.title}")
klass = reference_class(:merge_request)
+ data = data_attribute(project.id)
url = url_for_merge_request(merge_request, project)
- %(#{match})
else
diff --git a/lib/gitlab/markdown/reference_filter.rb b/lib/gitlab/markdown/reference_filter.rb
index a84bacd3d4f..47ee1d99da3 100644
--- a/lib/gitlab/markdown/reference_filter.rb
+++ b/lib/gitlab/markdown/reference_filter.rb
@@ -21,6 +21,22 @@ module Gitlab
result[:references] = Hash.new { |hash, type| hash[type] = [] }
end
+ # Returns a data attribute String to attach to a reference link
+ #
+ # id - Object ID
+ # type - Object type (default: :project)
+ #
+ # Examples:
+ #
+ # data_attribute(1) # => "data-project-id=\"1\""
+ # data_attribute(2, :user) # => "data-user-id=\"2\""
+ # data_attribute(3, :group) # => "data-group-id=\"3\""
+ #
+ # Returns a String
+ def data_attribute(id, type = :project)
+ %Q(data-#{type}-id="#{id}")
+ end
+
def escape_once(html)
ERB::Util.html_escape_once(html)
end
diff --git a/lib/gitlab/markdown/snippet_reference_filter.rb b/lib/gitlab/markdown/snippet_reference_filter.rb
index 174ba58af6c..92979a356dc 100644
--- a/lib/gitlab/markdown/snippet_reference_filter.rb
+++ b/lib/gitlab/markdown/snippet_reference_filter.rb
@@ -47,10 +47,11 @@ module Gitlab
title = escape_once("Snippet: #{snippet.title}")
klass = reference_class(:snippet)
+ data = data_attribute(project.id)
url = url_for_snippet(snippet, project)
- %(#{match})
else
diff --git a/lib/gitlab/markdown/user_reference_filter.rb b/lib/gitlab/markdown/user_reference_filter.rb
index c9972957182..a4aec7a05d1 100644
--- a/lib/gitlab/markdown/user_reference_filter.rb
+++ b/lib/gitlab/markdown/user_reference_filter.rb
@@ -83,18 +83,20 @@ module Gitlab
push_result(:user, *namespace.users)
url = urls.group_url(group, only_path: context[:only_path])
+ data = data_attribute(namespace.id, :group)
text = Group.reference_prefix + group
- %(#{text})
+ %(#{text})
end
def link_to_user(user, namespace)
push_result(:user, namespace.owner)
url = urls.user_url(user, only_path: context[:only_path])
+ data = data_attribute(namespace.owner_id, :user)
text = User.reference_prefix + user
- %(#{text})
+ %(#{text})
end
def user_can_reference_group?(group)
diff --git a/spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb b/spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
index e8391cc7aca..58155284486 100644
--- a/spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
@@ -80,6 +80,14 @@ module Gitlab::Markdown
expect(doc.css('a').first.attr('class')).to include 'custom'
end
+ it 'includes a data-project-id attribute' do
+ doc = filter("See #{reference}")
+ link = doc.css('a').first
+
+ expect(link).to have_attribute('data-project-id')
+ expect(link.attr('data-project-id')).to eq project.id.to_s
+ end
+
it 'supports an :only_path option' do
doc = filter("See #{reference}", only_path: true)
link = doc.css('a').first.attr('href')
diff --git a/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb b/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
index a10d43c9a02..05a02de4669 100644
--- a/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
@@ -76,6 +76,14 @@ module Gitlab::Markdown
expect(doc.css('a').first.attr('class')).to include 'custom'
end
+ it 'includes a data-project-id attribute' do
+ doc = filter("See #{reference}")
+ link = doc.css('a').first
+
+ expect(link).to have_attribute('data-project-id')
+ expect(link.attr('data-project-id')).to eq project.id.to_s
+ end
+
it 'supports an :only_path context' do
doc = filter("See #{reference}", only_path: true)
link = doc.css('a').first.attr('href')
diff --git a/spec/lib/gitlab/markdown/issue_reference_filter_spec.rb b/spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
index fa43d33794d..35b1ba5f132 100644
--- a/spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
@@ -73,6 +73,14 @@ module Gitlab::Markdown
expect(doc.css('a').first.attr('class')).to include 'custom'
end
+ it 'includes a data-project-id attribute' do
+ doc = filter("Issue #{reference}")
+ link = doc.css('a').first
+
+ expect(link).to have_attribute('data-project-id')
+ expect(link.attr('data-project-id')).to eq project.id.to_s
+ end
+
it 'supports an :only_path context' do
doc = filter("Issue #{reference}", only_path: true)
link = doc.css('a').first.attr('href')
diff --git a/spec/lib/gitlab/markdown/label_reference_filter_spec.rb b/spec/lib/gitlab/markdown/label_reference_filter_spec.rb
index e9f8ed277a5..fabe0411e46 100644
--- a/spec/lib/gitlab/markdown/label_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/label_reference_filter_spec.rb
@@ -30,6 +30,14 @@ module Gitlab::Markdown
expect(doc.css('a').first.attr('class')).to include 'custom'
end
+ it 'includes a data-project-id attribute' do
+ doc = filter("Label #{reference}")
+ link = doc.css('a').first
+
+ expect(link).to have_attribute('data-project-id')
+ expect(link.attr('data-project-id')).to eq project.id.to_s
+ end
+
it 'supports an :only_path context' do
doc = filter("Label #{reference}", only_path: true)
link = doc.css('a').first.attr('href')
diff --git a/spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb b/spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb
index 5945302a2da..5cef52b1916 100644
--- a/spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb
@@ -61,6 +61,14 @@ module Gitlab::Markdown
expect(doc.css('a').first.attr('class')).to include 'custom'
end
+ it 'includes a data-project-id attribute' do
+ doc = filter("Merge #{reference}")
+ link = doc.css('a').first
+
+ expect(link).to have_attribute('data-project-id')
+ expect(link.attr('data-project-id')).to eq project.id.to_s
+ end
+
it 'supports an :only_path context' do
doc = filter("Merge #{reference}", only_path: true)
link = doc.css('a').first.attr('href')
diff --git a/spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb b/spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
index 38619a3c07f..678b171e99e 100644
--- a/spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
@@ -60,6 +60,14 @@ module Gitlab::Markdown
expect(doc.css('a').first.attr('class')).to include 'custom'
end
+ it 'includes a data-project-id attribute' do
+ doc = filter("Snippet #{reference}")
+ link = doc.css('a').first
+
+ expect(link).to have_attribute('data-project-id')
+ expect(link.attr('data-project-id')).to eq project.id.to_s
+ end
+
it 'supports an :only_path context' do
doc = filter("Snippet #{reference}", only_path: true)
link = doc.css('a').first.attr('href')
diff --git a/spec/lib/gitlab/markdown/user_reference_filter_spec.rb b/spec/lib/gitlab/markdown/user_reference_filter_spec.rb
index 9c55b4ff38f..a5405e14a73 100644
--- a/spec/lib/gitlab/markdown/user_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/user_reference_filter_spec.rb
@@ -64,6 +64,14 @@ module Gitlab::Markdown
expect(doc.css('a').length).to eq 1
end
+ it 'includes a data-user-id attribute' do
+ doc = filter("Hey #{reference}")
+ link = doc.css('a').first
+
+ expect(link).to have_attribute('data-user-id')
+ expect(link.attr('data-user-id')).to eq user.namespace.owner_id.to_s
+ end
+
it 'adds to the results hash' do
result = pipeline_result("Hey #{reference}")
expect(result[:references][:user]).to eq [user]
@@ -85,6 +93,14 @@ module Gitlab::Markdown
expect(doc.css('a').first.attr('href')).to eq urls.group_url(group)
end
+ it 'includes a data-group-id attribute' do
+ doc = filter("Hey #{reference}", current_user: user)
+ link = doc.css('a').first
+
+ expect(link).to have_attribute('data-group-id')
+ expect(link.attr('data-group-id')).to eq group.id.to_s
+ end
+
it 'adds to the results hash' do
result = pipeline_result("Hey #{reference}", current_user: user)
expect(result[:references][:user]).to eq group.users