Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
2c55fd00
Commit
2c55fd00
authored
Feb 13, 2017
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add GFM support to nested groups
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
e5f446b7
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
36 additions
and
7 deletions
+36
-7
app/models/group.rb
app/models/group.rb
+1
-1
app/models/user.rb
app/models/user.rb
+1
-1
app/services/projects/participants_service.rb
app/services/projects/participants_service.rb
+1
-1
lib/banzai/filter/abstract_reference_filter.rb
lib/banzai/filter/abstract_reference_filter.rb
+1
-1
lib/banzai/filter/user_reference_filter.rb
lib/banzai/filter/user_reference_filter.rb
+3
-3
lib/gitlab/regex.rb
lib/gitlab/regex.rb
+4
-0
spec/lib/banzai/filter/user_reference_filter_spec.rb
spec/lib/banzai/filter/user_reference_filter_spec.rb
+13
-0
spec/lib/gitlab/regex_spec.rb
spec/lib/gitlab/regex_spec.rb
+12
-0
No files found.
app/models/group.rb
View file @
2c55fd00
...
...
@@ -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
...
...
app/models/user.rb
View file @
2c55fd00
...
...
@@ -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_RE
F_RE
GEX_STR
}
)
}x
end
end
...
...
app/services/projects/participants_service.rb
View file @
2c55fd00
...
...
@@ -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
...
...
lib/banzai/filter/abstract_reference_filter.rb
View file @
2c55fd00
...
...
@@ -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
...
...
lib/banzai/filter/user_reference_filter.rb
View file @
2c55fd00
...
...
@@ -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
...
...
lib/gitlab/regex.rb
View file @
2c55fd00
...
...
@@ -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
...
...
spec/lib/banzai/filter/user_reference_filter_spec.rb
View file @
2c55fd00
...
...
@@ -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>\.\)/
)
...
...
spec/lib/gitlab/regex_spec.rb
View file @
2c55fd00
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment