summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/gitlab/markdown/commit_range_reference_filter.rb2
-rw-r--r--lib/gitlab/markdown/commit_reference_filter.rb2
-rw-r--r--lib/gitlab/markdown/issue_reference_filter.rb3
-rw-r--r--lib/gitlab/markdown/label_reference_filter.rb6
-rw-r--r--lib/gitlab/markdown/merge_request_reference_filter.rb2
-rw-r--r--lib/gitlab/markdown/snippet_reference_filter.rb2
-rw-r--r--lib/gitlab/markdown/user_reference_filter.rb7
-rw-r--r--spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb10
-rw-r--r--spec/lib/gitlab/markdown/commit_reference_filter_spec.rb10
-rw-r--r--spec/lib/gitlab/markdown/issue_reference_filter_spec.rb12
-rw-r--r--spec/lib/gitlab/markdown/label_reference_filter_spec.rb5
-rw-r--r--spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb10
-rw-r--r--spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb10
-rw-r--r--spec/lib/gitlab/markdown/user_reference_filter_spec.rb66
14 files changed, 129 insertions, 18 deletions
diff --git a/lib/gitlab/markdown/commit_range_reference_filter.rb b/lib/gitlab/markdown/commit_range_reference_filter.rb
index baa97bee9bf..5e5e7adc238 100644
--- a/lib/gitlab/markdown/commit_range_reference_filter.rb
+++ b/lib/gitlab/markdown/commit_range_reference_filter.rb
@@ -59,6 +59,8 @@ module Gitlab
from_id, to_id = split_commit_range(commit_range)
if valid_range?(project, from_id, to_id)
+ push_result(:commit_range, [commit(from_id), commit(to_id)])
+
url = url_for_commit_range(project, from_id, to_id)
title = "Commits #{from_id} through #{to_id}"
diff --git a/lib/gitlab/markdown/commit_reference_filter.rb b/lib/gitlab/markdown/commit_reference_filter.rb
index 66598127f6e..41fb03cdd41 100644
--- a/lib/gitlab/markdown/commit_reference_filter.rb
+++ b/lib/gitlab/markdown/commit_reference_filter.rb
@@ -48,6 +48,8 @@ module Gitlab
project = self.project_from_ref(project_ref)
if commit = commit_from_ref(project, commit_ref)
+ push_result(:commit, commit)
+
url = url_for_commit(project, commit)
title = escape_once(commit.link_title)
diff --git a/lib/gitlab/markdown/issue_reference_filter.rb b/lib/gitlab/markdown/issue_reference_filter.rb
index c9267cc3e9d..4b360369d37 100644
--- a/lib/gitlab/markdown/issue_reference_filter.rb
+++ b/lib/gitlab/markdown/issue_reference_filter.rb
@@ -48,6 +48,9 @@ module Gitlab
project = self.project_from_ref(project_ref)
if project && project.issue_exists?(issue)
+ # FIXME (rspeicher): Law of Demeter
+ push_result(:issue, project.issues.where(iid: issue).first)
+
url = url_for_issue(issue, project, only_path: context[:only_path])
title = escape_once("Issue: #{title_for_issue(issue, project)}")
diff --git a/lib/gitlab/markdown/label_reference_filter.rb b/lib/gitlab/markdown/label_reference_filter.rb
index 4c21192c0d3..a357f28458d 100644
--- a/lib/gitlab/markdown/label_reference_filter.rb
+++ b/lib/gitlab/markdown/label_reference_filter.rb
@@ -52,11 +52,13 @@ module Gitlab
params = label_params(id, name)
if label = project.labels.find_by(params)
- url = url_for_label(project, label)
+ push_result(:label, label)
+ url = url_for_label(project, label)
klass = reference_class(:label)
- %(<a href="#{url}" class="#{klass}">#{render_colored_label(label)}</a>)
+ %(<a href="#{url}"
+ class="#{klass}">#{render_colored_label(label)}</a>)
else
match
end
diff --git a/lib/gitlab/markdown/merge_request_reference_filter.rb b/lib/gitlab/markdown/merge_request_reference_filter.rb
index 40239523cda..7c28fe112ef 100644
--- a/lib/gitlab/markdown/merge_request_reference_filter.rb
+++ b/lib/gitlab/markdown/merge_request_reference_filter.rb
@@ -48,6 +48,8 @@ module Gitlab
project = self.project_from_ref(project_ref)
if project && merge_request = project.merge_requests.find_by(iid: id)
+ push_result(:merge_request, merge_request)
+
title = escape_once("Merge Request: #{merge_request.title}")
klass = reference_class(:merge_request)
diff --git a/lib/gitlab/markdown/snippet_reference_filter.rb b/lib/gitlab/markdown/snippet_reference_filter.rb
index ada67de992b..64a0a2696f7 100644
--- a/lib/gitlab/markdown/snippet_reference_filter.rb
+++ b/lib/gitlab/markdown/snippet_reference_filter.rb
@@ -48,6 +48,8 @@ module Gitlab
project = self.project_from_ref(project_ref)
if project && snippet = project.snippets.find_by(id: id)
+ push_result(:snippet, snippet)
+
title = escape_once("Snippet: #{snippet.title}")
klass = reference_class(:snippet)
diff --git a/lib/gitlab/markdown/user_reference_filter.rb b/lib/gitlab/markdown/user_reference_filter.rb
index 5fc8ed55fe2..d3af206335d 100644
--- a/lib/gitlab/markdown/user_reference_filter.rb
+++ b/lib/gitlab/markdown/user_reference_filter.rb
@@ -44,18 +44,25 @@ module Gitlab
klass = reference_class(:project_member)
if user == 'all'
+ # FIXME (rspeicher): Law of Demeter
+ push_result(:user, project.team.members.flatten)
+
url = link_to_all(project)
%(<a href="#{url}" class="#{klass}">@#{user}</a>)
elsif namespace = Namespace.find_by(path: user)
if namespace.is_a?(Group)
if user_can_reference_group?(namespace)
+ push_result(:user, namespace.users)
+
url = group_url(user, only_path: context[:only_path])
%(<a href="#{url}" class="#{klass}">@#{user}</a>)
else
match
end
else
+ push_result(:user, namespace.owner)
+
url = user_url(user, only_path: context[:only_path])
%(<a href="#{url}" class="#{klass}">@#{user}</a>)
end
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 f0804ce0056..6bfe7bb3615 100644
--- a/spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
@@ -81,6 +81,11 @@ module Gitlab::Markdown
expect(link).not_to match %r(https?://)
expect(link).to eq urls.namespace_project_compare_url(project.namespace, project, from: commit1.id, to: commit2.id, only_path: true)
end
+
+ it 'adds to the results hash' do
+ result = pipeline_result("See #{reference}")
+ expect(result[:references][:commit_range]).not_to be_empty
+ end
end
context 'cross-project reference' do
@@ -112,6 +117,11 @@ module Gitlab::Markdown
exp = act = "Fixed #{project2.path_with_namespace}##{commit1.id}...#{commit2.id.reverse}"
expect(filter(act).to_html).to eq exp
end
+
+ it 'adds to the results hash' do
+ result = pipeline_result("See #{reference}")
+ expect(result[:references][:commit_range]).not_to be_empty
+ end
end
context 'when user cannot access reference' do
diff --git a/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb b/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
index f792d7f696e..5efda4f9aa4 100644
--- a/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
@@ -75,6 +75,11 @@ module Gitlab::Markdown
expect(link).not_to match %r(https?://)
expect(link).to eq urls.namespace_project_commit_url(project.namespace, project, reference, only_path: true)
end
+
+ it 'adds to the results hash' do
+ result = pipeline_result("See #{reference}")
+ expect(result[:references][:commit]).not_to be_empty
+ end
end
context 'cross-project reference' do
@@ -102,6 +107,11 @@ module Gitlab::Markdown
exp = act = "Committed #{project2.path_with_namespace}##{commit.id.reverse}"
expect(filter(act).to_html).to eq exp
end
+
+ it 'adds to the results hash' do
+ result = pipeline_result("See #{reference}")
+ expect(result[:references][:commit]).not_to be_empty
+ end
end
context 'when user cannot access reference' do
diff --git a/spec/lib/gitlab/markdown/issue_reference_filter_spec.rb b/spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
index f95b37d6954..393bf32e196 100644
--- a/spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
@@ -34,7 +34,7 @@ module Gitlab::Markdown
end
it 'links to a valid reference' do
- doc = filter("See #{reference}")
+ doc = filter("Fixed #{reference}")
expect(doc.css('a').first.attr('href')).
to eq helper.url_for_issue(issue.iid, project)
@@ -81,6 +81,11 @@ module Gitlab::Markdown
expect(link).not_to match %r(https?://)
expect(link).to eq helper.url_for_issue(issue.iid, project, only_path: true)
end
+
+ it 'adds to the results hash' do
+ result = pipeline_result("Fixed #{reference}")
+ expect(result[:references][:issue]).to eq [issue]
+ end
end
context 'cross-project reference' do
@@ -117,6 +122,11 @@ module Gitlab::Markdown
expect(filter(act).to_html).to eq exp
end
+
+ it 'adds to the results hash' do
+ result = pipeline_result("Fixed #{reference}")
+ expect(result[:references][:issue]).to eq [issue]
+ end
end
context 'when user cannot access reference' do
diff --git a/spec/lib/gitlab/markdown/label_reference_filter_spec.rb b/spec/lib/gitlab/markdown/label_reference_filter_spec.rb
index c84e568e172..9f898837466 100644
--- a/spec/lib/gitlab/markdown/label_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/label_reference_filter_spec.rb
@@ -39,6 +39,11 @@ module Gitlab::Markdown
expect(link).to eq urls.namespace_project_issues_url(project.namespace, project, label_name: label.name, only_path: true)
end
+ it 'adds to the results hash' do
+ result = pipeline_result("Label #{reference}")
+ expect(result[:references][:label]).to eq [label]
+ end
+
describe 'label span element' do
it 'includes default classes' do
doc = filter("Label #{reference}")
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 0f66442269b..d6e745114f2 100644
--- a/spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb
@@ -69,6 +69,11 @@ module Gitlab::Markdown
expect(link).not_to match %r(https?://)
expect(link).to eq urls.namespace_project_merge_request_url(project.namespace, project, merge, only_path: true)
end
+
+ it 'adds to the results hash' do
+ result = pipeline_result("Merge #{reference}")
+ expect(result[:references][:merge_request]).to eq [merge]
+ end
end
context 'cross-project reference' do
@@ -98,6 +103,11 @@ module Gitlab::Markdown
expect(filter(act).to_html).to eq exp
end
+
+ it 'adds to the results hash' do
+ result = pipeline_result("Merge #{reference}")
+ expect(result[:references][:merge_request]).to eq [merge]
+ end
end
context 'when user cannot access reference' do
diff --git a/spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb b/spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
index 79533a90b55..a4b331157af 100644
--- a/spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
@@ -68,6 +68,11 @@ module Gitlab::Markdown
expect(link).not_to match %r(https?://)
expect(link).to eq urls.namespace_project_snippet_url(project.namespace, project, snippet, only_path: true)
end
+
+ it 'adds to the results hash' do
+ result = pipeline_result("Snippet #{reference}")
+ expect(result[:references][:snippet]).to eq [snippet]
+ end
end
context 'cross-project reference' do
@@ -96,6 +101,11 @@ module Gitlab::Markdown
expect(filter(act).to_html).to eq exp
end
+
+ it 'adds to the results hash' do
+ result = pipeline_result("Snippet #{reference}")
+ expect(result[:references][:snippet]).to eq [snippet]
+ end
end
context 'when user cannot access reference' do
diff --git a/spec/lib/gitlab/markdown/user_reference_filter_spec.rb b/spec/lib/gitlab/markdown/user_reference_filter_spec.rb
index a5eb927072e..f5a14367311 100644
--- a/spec/lib/gitlab/markdown/user_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/user_reference_filter_spec.rb
@@ -24,9 +24,29 @@ module Gitlab::Markdown
end
end
+ context 'mentioning @all' do
+ before do
+ project.team << [project.creator, :developer]
+ end
+
+ it 'supports a special @all mention' do
+ doc = filter("Hey @all")
+ expect(doc.css('a').length).to eq 1
+ expect(doc.css('a').first.attr('href'))
+ .to eq urls.namespace_project_url(project.namespace, project)
+ end
+
+ it 'adds to the results hash' do
+ result = pipeline_result('Hey @all')
+ expect(result[:references][:user]).to eq [[project.creator]]
+ end
+ end
+
context 'mentioning a user' do
+ let(:reference) { "@#{user.username}" }
+
it 'links to a User' do
- doc = filter("Hey @#{user.username}")
+ doc = filter("Hey #{reference}")
expect(doc.css('a').first.attr('href')).to eq urls.user_url(user)
end
@@ -45,22 +65,45 @@ module Gitlab::Markdown
doc = filter("Hey @#{user.username}")
expect(doc.css('a').length).to eq 1
end
+
+ it 'adds to the results hash' do
+ result = pipeline_result("Hey #{reference}")
+ expect(result[:references][:user]).to eq [user]
+ end
end
context 'mentioning a group' do
let(:group) { create(:group) }
let(:user) { create(:user) }
- it 'links to a Group that the current user can read' do
- group.add_user(user, Gitlab::Access::DEVELOPER)
+ let(:reference) { "@#{group.name}" }
+
+ context 'that the current user can read' do
+ before do
+ group.add_user(user, Gitlab::Access::DEVELOPER)
+ end
- doc = filter("Hey @#{group.name}", current_user: user)
- expect(doc.css('a').first.attr('href')).to eq urls.group_url(group)
+ it 'links to the Group' do
+ doc = filter("Hey #{reference}", current_user: user)
+ expect(doc.css('a').first.attr('href')).to eq urls.group_url(group)
+ end
+
+ it 'adds to the results hash' do
+ result = pipeline_result("Hey #{reference}", current_user: user)
+ expect(result[:references][:user]).to eq [group.users]
+ end
end
- it 'ignores references to a Group that the current user cannot read' do
- doc = filter("Hey @#{group.name}", current_user: user)
- expect(doc.to_html).to eq "Hey @#{group.name}"
+ context 'that the current user cannot read' do
+ it 'ignores references to the Group' do
+ doc = filter("Hey #{reference}", current_user: user)
+ expect(doc.to_html).to eq "Hey #{reference}"
+ end
+
+ it 'does not add to the results hash' do
+ result = pipeline_result("Hey #{reference}", current_user: user)
+ expect(result[:references][:user]).to eq []
+ end
end
end
@@ -70,13 +113,6 @@ module Gitlab::Markdown
expect(doc.to_html).to match(/\(<a.+>@#{user.username}<\/a>\.\)/)
end
- it 'supports a special @all mention' do
- doc = filter("Hey @all")
- expect(doc.css('a').length).to eq 1
- expect(doc.css('a').first.attr('href'))
- .to eq urls.namespace_project_url(project.namespace, project)
- end
-
it 'includes default classes' do
doc = filter("Hey @#{user.username}")
expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-project_member'