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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
d2bd6067
Commit
d2bd6067
authored
Mar 27, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Mentionable mentioned users to use ReferenceExtractor.
parent
ca58e369
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
19 deletions
+16
-19
app/models/concerns/mentionable.rb
app/models/concerns/mentionable.rb
+6
-17
lib/gitlab/reference_extractor.rb
lib/gitlab/reference_extractor.rb
+10
-2
No files found.
app/models/concerns/mentionable.rb
View file @
d2bd6067
...
@@ -43,28 +43,17 @@ module Mentionable
...
@@ -43,28 +43,17 @@ module Mentionable
end
end
def
mentioned_users
def
mentioned_users
users
=
[]
return
[]
if
mentionable_text
.
blank?
return
users
if
mentionable_text
.
blank?
has_project
=
self
.
respond_to?
:project
ext
=
Gitlab
::
ReferenceExtractor
.
new
(
self
.
project
)
matches
=
mentionable_text
.
scan
(
/@[a-zA-Z][a-zA-Z0-9_\-\.]*/
)
ext
.
analyze
(
text
)
matches
.
each
do
|
match
|
ext
.
users
.
uniq
identifier
=
match
.
delete
"@"
if
identifier
==
"all"
users
.
push
(
*
project
.
team
.
members
.
flatten
)
elsif
namespace
=
Namespace
.
find_by
(
path:
identifier
)
if
namespace
.
is_a?
(
Group
)
users
.
push
(
*
namespace
.
users
)
else
users
<<
namespace
.
owner
end
end
end
users
.
uniq
end
end
# Extract GFM references to other Mentionables from this Mentionable. Always excludes its #local_reference.
# Extract GFM references to other Mentionables from this Mentionable. Always excludes its #local_reference.
def
references
(
p
=
project
,
text
=
mentionable_text
)
def
references
(
p
=
project
,
text
=
mentionable_text
)
return
[]
if
text
.
blank?
return
[]
if
text
.
blank?
ext
=
Gitlab
::
ReferenceExtractor
.
new
(
p
)
ext
=
Gitlab
::
ReferenceExtractor
.
new
(
p
)
ext
.
analyze
(
text
)
ext
.
analyze
(
text
)
...
...
lib/gitlab/reference_extractor.rb
View file @
d2bd6067
...
@@ -34,8 +34,16 @@ module Gitlab
...
@@ -34,8 +34,16 @@ module Gitlab
def
users
def
users
references
[
:users
].
map
do
|
entry
|
references
[
:users
].
map
do
|
entry
|
project
.
users
.
where
(
username:
entry
[
:id
]).
first
if
entry
[
:id
]
==
"all"
end
.
compact
project
.
team
.
members
.
flatten
elsif
namespace
=
Namespace
.
find_by
(
path:
entry
[
:id
])
if
namespace
.
is_a?
(
Group
)
namespace
.
users
else
namespace
.
owner
end
end
end
.
flatten
.
compact
end
end
def
labels
def
labels
...
...
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