Commit a6defd15 authored by Robert Speicher's avatar Robert Speicher

Add results to reference filters

parent 85082de7
...@@ -59,6 +59,8 @@ module Gitlab ...@@ -59,6 +59,8 @@ module Gitlab
from_id, to_id = split_commit_range(commit_range) from_id, to_id = split_commit_range(commit_range)
if valid_range?(project, from_id, to_id) 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) url = url_for_commit_range(project, from_id, to_id)
title = "Commits #{from_id} through #{to_id}" title = "Commits #{from_id} through #{to_id}"
......
...@@ -48,6 +48,8 @@ module Gitlab ...@@ -48,6 +48,8 @@ module Gitlab
project = self.project_from_ref(project_ref) project = self.project_from_ref(project_ref)
if commit = commit_from_ref(project, commit_ref) if commit = commit_from_ref(project, commit_ref)
push_result(:commit, commit)
url = url_for_commit(project, commit) url = url_for_commit(project, commit)
title = escape_once(commit.link_title) title = escape_once(commit.link_title)
......
...@@ -48,6 +48,9 @@ module Gitlab ...@@ -48,6 +48,9 @@ module Gitlab
project = self.project_from_ref(project_ref) project = self.project_from_ref(project_ref)
if project && project.issue_exists?(issue) 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]) url = url_for_issue(issue, project, only_path: context[:only_path])
title = escape_once("Issue: #{title_for_issue(issue, project)}") title = escape_once("Issue: #{title_for_issue(issue, project)}")
......
...@@ -52,11 +52,13 @@ module Gitlab ...@@ -52,11 +52,13 @@ module Gitlab
params = label_params(id, name) params = label_params(id, name)
if label = project.labels.find_by(params) 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) 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 else
match match
end end
......
...@@ -48,6 +48,8 @@ module Gitlab ...@@ -48,6 +48,8 @@ module Gitlab
project = self.project_from_ref(project_ref) project = self.project_from_ref(project_ref)
if project && merge_request = project.merge_requests.find_by(iid: id) 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}") title = escape_once("Merge Request: #{merge_request.title}")
klass = reference_class(:merge_request) klass = reference_class(:merge_request)
......
...@@ -48,6 +48,8 @@ module Gitlab ...@@ -48,6 +48,8 @@ module Gitlab
project = self.project_from_ref(project_ref) project = self.project_from_ref(project_ref)
if project && snippet = project.snippets.find_by(id: id) if project && snippet = project.snippets.find_by(id: id)
push_result(:snippet, snippet)
title = escape_once("Snippet: #{snippet.title}") title = escape_once("Snippet: #{snippet.title}")
klass = reference_class(:snippet) klass = reference_class(:snippet)
......
...@@ -44,18 +44,25 @@ module Gitlab ...@@ -44,18 +44,25 @@ module Gitlab
klass = reference_class(:project_member) klass = reference_class(:project_member)
if user == 'all' if user == 'all'
# FIXME (rspeicher): Law of Demeter
push_result(:user, project.team.members.flatten)
url = link_to_all(project) url = link_to_all(project)
%(<a href="#{url}" class="#{klass}">@#{user}</a>) %(<a href="#{url}" class="#{klass}">@#{user}</a>)
elsif namespace = Namespace.find_by(path: user) elsif namespace = Namespace.find_by(path: user)
if namespace.is_a?(Group) if namespace.is_a?(Group)
if user_can_reference_group?(namespace) if user_can_reference_group?(namespace)
push_result(:user, namespace.users)
url = group_url(user, only_path: context[:only_path]) url = group_url(user, only_path: context[:only_path])
%(<a href="#{url}" class="#{klass}">@#{user}</a>) %(<a href="#{url}" class="#{klass}">@#{user}</a>)
else else
match match
end end
else else
push_result(:user, namespace.owner)
url = user_url(user, only_path: context[:only_path]) url = user_url(user, only_path: context[:only_path])
%(<a href="#{url}" class="#{klass}">@#{user}</a>) %(<a href="#{url}" class="#{klass}">@#{user}</a>)
end end
......
...@@ -81,6 +81,11 @@ module Gitlab::Markdown ...@@ -81,6 +81,11 @@ module Gitlab::Markdown
expect(link).not_to match %r(https?://) 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) expect(link).to eq urls.namespace_project_compare_url(project.namespace, project, from: commit1.id, to: commit2.id, only_path: true)
end end
it 'adds to the results hash' do
result = pipeline_result("See #{reference}")
expect(result[:references][:commit_range]).not_to be_empty
end
end end
context 'cross-project reference' do context 'cross-project reference' do
...@@ -112,6 +117,11 @@ module Gitlab::Markdown ...@@ -112,6 +117,11 @@ module Gitlab::Markdown
exp = act = "Fixed #{project2.path_with_namespace}##{commit1.id}...#{commit2.id.reverse}" exp = act = "Fixed #{project2.path_with_namespace}##{commit1.id}...#{commit2.id.reverse}"
expect(filter(act).to_html).to eq exp expect(filter(act).to_html).to eq exp
end end
it 'adds to the results hash' do
result = pipeline_result("See #{reference}")
expect(result[:references][:commit_range]).not_to be_empty
end
end end
context 'when user cannot access reference' do context 'when user cannot access reference' do
......
...@@ -75,6 +75,11 @@ module Gitlab::Markdown ...@@ -75,6 +75,11 @@ module Gitlab::Markdown
expect(link).not_to match %r(https?://) expect(link).not_to match %r(https?://)
expect(link).to eq urls.namespace_project_commit_url(project.namespace, project, reference, only_path: true) expect(link).to eq urls.namespace_project_commit_url(project.namespace, project, reference, only_path: true)
end end
it 'adds to the results hash' do
result = pipeline_result("See #{reference}")
expect(result[:references][:commit]).not_to be_empty
end
end end
context 'cross-project reference' do context 'cross-project reference' do
...@@ -102,6 +107,11 @@ module Gitlab::Markdown ...@@ -102,6 +107,11 @@ module Gitlab::Markdown
exp = act = "Committed #{project2.path_with_namespace}##{commit.id.reverse}" exp = act = "Committed #{project2.path_with_namespace}##{commit.id.reverse}"
expect(filter(act).to_html).to eq exp expect(filter(act).to_html).to eq exp
end end
it 'adds to the results hash' do
result = pipeline_result("See #{reference}")
expect(result[:references][:commit]).not_to be_empty
end
end end
context 'when user cannot access reference' do context 'when user cannot access reference' do
......
...@@ -34,7 +34,7 @@ module Gitlab::Markdown ...@@ -34,7 +34,7 @@ module Gitlab::Markdown
end end
it 'links to a valid reference' do it 'links to a valid reference' do
doc = filter("See #{reference}") doc = filter("Fixed #{reference}")
expect(doc.css('a').first.attr('href')). expect(doc.css('a').first.attr('href')).
to eq helper.url_for_issue(issue.iid, project) to eq helper.url_for_issue(issue.iid, project)
...@@ -81,6 +81,11 @@ module Gitlab::Markdown ...@@ -81,6 +81,11 @@ module Gitlab::Markdown
expect(link).not_to match %r(https?://) expect(link).not_to match %r(https?://)
expect(link).to eq helper.url_for_issue(issue.iid, project, only_path: true) expect(link).to eq helper.url_for_issue(issue.iid, project, only_path: true)
end end
it 'adds to the results hash' do
result = pipeline_result("Fixed #{reference}")
expect(result[:references][:issue]).to eq [issue]
end
end end
context 'cross-project reference' do context 'cross-project reference' do
...@@ -117,6 +122,11 @@ module Gitlab::Markdown ...@@ -117,6 +122,11 @@ module Gitlab::Markdown
expect(filter(act).to_html).to eq exp expect(filter(act).to_html).to eq exp
end end
it 'adds to the results hash' do
result = pipeline_result("Fixed #{reference}")
expect(result[:references][:issue]).to eq [issue]
end
end end
context 'when user cannot access reference' do context 'when user cannot access reference' do
......
...@@ -39,6 +39,11 @@ module Gitlab::Markdown ...@@ -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) expect(link).to eq urls.namespace_project_issues_url(project.namespace, project, label_name: label.name, only_path: true)
end 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 describe 'label span element' do
it 'includes default classes' do it 'includes default classes' do
doc = filter("Label #{reference}") doc = filter("Label #{reference}")
......
...@@ -69,6 +69,11 @@ module Gitlab::Markdown ...@@ -69,6 +69,11 @@ module Gitlab::Markdown
expect(link).not_to match %r(https?://) expect(link).not_to match %r(https?://)
expect(link).to eq urls.namespace_project_merge_request_url(project.namespace, project, merge, only_path: true) expect(link).to eq urls.namespace_project_merge_request_url(project.namespace, project, merge, only_path: true)
end end
it 'adds to the results hash' do
result = pipeline_result("Merge #{reference}")
expect(result[:references][:merge_request]).to eq [merge]
end
end end
context 'cross-project reference' do context 'cross-project reference' do
...@@ -98,6 +103,11 @@ module Gitlab::Markdown ...@@ -98,6 +103,11 @@ module Gitlab::Markdown
expect(filter(act).to_html).to eq exp expect(filter(act).to_html).to eq exp
end end
it 'adds to the results hash' do
result = pipeline_result("Merge #{reference}")
expect(result[:references][:merge_request]).to eq [merge]
end
end end
context 'when user cannot access reference' do context 'when user cannot access reference' do
......
...@@ -68,6 +68,11 @@ module Gitlab::Markdown ...@@ -68,6 +68,11 @@ module Gitlab::Markdown
expect(link).not_to match %r(https?://) expect(link).not_to match %r(https?://)
expect(link).to eq urls.namespace_project_snippet_url(project.namespace, project, snippet, only_path: true) expect(link).to eq urls.namespace_project_snippet_url(project.namespace, project, snippet, only_path: true)
end end
it 'adds to the results hash' do
result = pipeline_result("Snippet #{reference}")
expect(result[:references][:snippet]).to eq [snippet]
end
end end
context 'cross-project reference' do context 'cross-project reference' do
...@@ -96,6 +101,11 @@ module Gitlab::Markdown ...@@ -96,6 +101,11 @@ module Gitlab::Markdown
expect(filter(act).to_html).to eq exp expect(filter(act).to_html).to eq exp
end end
it 'adds to the results hash' do
result = pipeline_result("Snippet #{reference}")
expect(result[:references][:snippet]).to eq [snippet]
end
end end
context 'when user cannot access reference' do context 'when user cannot access reference' do
......
...@@ -24,9 +24,29 @@ module Gitlab::Markdown ...@@ -24,9 +24,29 @@ module Gitlab::Markdown
end end
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 context 'mentioning a user' do
let(:reference) { "@#{user.username}" }
it 'links to a User' do 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) expect(doc.css('a').first.attr('href')).to eq urls.user_url(user)
end end
...@@ -45,22 +65,45 @@ module Gitlab::Markdown ...@@ -45,22 +65,45 @@ module Gitlab::Markdown
doc = filter("Hey @#{user.username}") doc = filter("Hey @#{user.username}")
expect(doc.css('a').length).to eq 1 expect(doc.css('a').length).to eq 1
end end
it 'adds to the results hash' do
result = pipeline_result("Hey #{reference}")
expect(result[:references][:user]).to eq [user]
end
end end
context 'mentioning a group' do context 'mentioning a group' do
let(:group) { create(:group) } let(:group) { create(:group) }
let(:user) { create(:user) } let(:user) { create(:user) }
it 'links to a Group that the current user can read' do let(:reference) { "@#{group.name}" }
group.add_user(user, Gitlab::Access::DEVELOPER)
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) it 'links to the Group' do
expect(doc.css('a').first.attr('href')).to eq urls.group_url(group) 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 end
it 'ignores references to a Group that the current user cannot read' do context 'that the current user cannot read' do
doc = filter("Hey @#{group.name}", current_user: user) it 'ignores references to the Group' do
expect(doc.to_html).to eq "Hey @#{group.name}" 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
end end
...@@ -70,13 +113,6 @@ module Gitlab::Markdown ...@@ -70,13 +113,6 @@ module Gitlab::Markdown
expect(doc.to_html).to match(/\(<a.+>@#{user.username}<\/a>\.\)/) expect(doc.to_html).to match(/\(<a.+>@#{user.username}<\/a>\.\)/)
end 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 it 'includes default classes' do
doc = filter("Hey @#{user.username}") doc = filter("Hey @#{user.username}")
expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-project_member' expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-project_member'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment