Merge branch 'dz-nested-groups-gfm-alt' into 'master'

Add GFM support to nested groups

See merge request !9184
This commit is contained in:
Dmitriy Zaporozhets 2017-02-14 09:38:16 +00:00
commit c867fbab24
8 changed files with 36 additions and 7 deletions

View file

@ -81,7 +81,7 @@ class Group < Namespace
end
def to_reference(_from_project = nil, full: nil)
"#{self.class.reference_prefix}#{name}"
"#{self.class.reference_prefix}#{full_path}"
end
def web_url

View file

@ -335,7 +335,7 @@ class User < ActiveRecord::Base
def reference_pattern
%r{
#{Regexp.escape(reference_prefix)}
(?<user>#{Gitlab::Regex::NAMESPACE_REGEX_STR})
(?<user>#{Gitlab::Regex::NAMESPACE_REF_REGEX_STR})
}x
end
end

View file

@ -36,7 +36,7 @@ module Projects
def groups
current_user.authorized_groups.sort_by(&:path).map do |group|
count = group.users.count
{ username: group.path, name: group.name, count: count, avatar_url: group.avatar_url }
{ username: group.full_path, name: group.full_name, count: count, avatar_url: group.avatar_url }
end
end

View file

@ -285,7 +285,7 @@ module Banzai
end
def current_project_namespace_path
@current_project_namespace_path ||= project.namespace.path
@current_project_namespace_path ||= project.namespace.full_path
end
private

View file

@ -75,8 +75,8 @@ module Banzai
# corresponding Namespace objects.
def namespaces
@namespaces ||=
Namespace.where(path: usernames).each_with_object({}) do |row, hash|
hash[row.path] = row
Namespace.where_full_path_in(usernames).each_with_object({}) do |row, hash|
hash[row.full_path] = row
end
end
@ -122,7 +122,7 @@ module Banzai
def link_to_namespace(namespace, link_content: nil)
if namespace.is_a?(Group)
link_to_group(namespace.path, namespace, link_content: link_content)
link_to_group(namespace.full_path, namespace, link_content: link_content)
else
link_to_user(namespace.path, namespace, link_content: link_content)
end

View file

@ -13,6 +13,10 @@ module Gitlab
NAMESPACE_REGEX_STR = '(?:' + NAMESPACE_REGEX_STR_SIMPLE + ')(?<!\.git|\.atom)'.freeze
PROJECT_REGEX_STR = PATH_REGEX_STR + '(?<!\.git|\.atom)'.freeze
# Same as NAMESPACE_REGEX_STR but allows `/` in the path.
# So `group/subgroup` will match this regex but not NAMESPACE_REGEX_STR
NAMESPACE_REF_REGEX_STR = '(?:[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.\/]*[a-zA-Z0-9_\-]|[a-zA-Z0-9_])(?<!\.git|\.atom)'.freeze
def namespace_regex
@namespace_regex ||= /\A#{NAMESPACE_REGEX_STR}\z/.freeze
end

View file

@ -112,6 +112,19 @@ describe Banzai::Filter::UserReferenceFilter, lib: true do
end
end
context 'mentioning a nested group' do
it_behaves_like 'a reference containing an element node'
let(:group) { create(:group, :nested) }
let(:reference) { group.to_reference }
it 'links to the nested group' do
doc = reference_filter("Hey #{reference}")
expect(doc.css('a').first.attr('href')).to eq urls.group_url(group)
end
end
it 'links with adjacent text' do
doc = reference_filter("Mention me (#{reference}.)")
expect(doc.to_html).to match(/\(<a.+>#{reference}<\/a>\.\)/)

View file

@ -50,4 +50,16 @@ describe Gitlab::Regex, lib: true do
it { is_expected.not_to match('9foo') }
it { is_expected.not_to match('foo-') }
end
describe 'NAMESPACE_REF_REGEX_STR' do
subject { %r{\A#{Gitlab::Regex::NAMESPACE_REF_REGEX_STR}\z} }
it { is_expected.to match('gitlab.org') }
it { is_expected.to match('gitlab.org/gitlab-git') }
it { is_expected.not_to match('gitlab.org.') }
it { is_expected.not_to match('gitlab.org/') }
it { is_expected.not_to match('/gitlab.org') }
it { is_expected.not_to match('gitlab.git') }
it { is_expected.not_to match('gitlab git') }
end
end