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
Boxiang Sun
gitlab-ce
Commits
b492f0f8
Commit
b492f0f8
authored
Apr 03, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor ReferenceExtractor.
parent
9d647197
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
29 deletions
+28
-29
lib/gitlab/reference_extractor.rb
lib/gitlab/reference_extractor.rb
+28
-29
No files found.
lib/gitlab/reference_extractor.rb
View file @
b492f0f8
...
@@ -8,8 +8,6 @@ module Gitlab
...
@@ -8,8 +8,6 @@ module Gitlab
def
initialize
(
project
,
current_user
=
nil
)
def
initialize
(
project
,
current_user
=
nil
)
@project
=
project
@project
=
project
@current_user
=
current_user
@current_user
=
current_user
@references
=
Hash
.
new
{
[]
}
end
end
def
can?
(
user
,
action
,
subject
)
def
can?
(
user
,
action
,
subject
)
...
@@ -23,6 +21,7 @@ module Gitlab
...
@@ -23,6 +21,7 @@ module Gitlab
text
.
gsub!
(
%r{<pre>.*?</pre>|<code>.*?</code>}m
)
{
|
match
|
''
}
text
.
gsub!
(
%r{<pre>.*?</pre>|<code>.*?</code>}m
)
{
|
match
|
''
}
text
.
gsub!
(
%r{^```.*?^```}m
)
{
|
match
|
''
}
text
.
gsub!
(
%r{^```.*?^```}m
)
{
|
match
|
''
}
@references
=
Hash
.
new
{
|
hash
,
type
|
hash
[
type
]
=
[]
}
parse_references
(
text
)
parse_references
(
text
)
end
end
...
@@ -30,66 +29,66 @@ module Gitlab
...
@@ -30,66 +29,66 @@ module Gitlab
# model objects.
# model objects.
def
users
def
users
references
[
:user
s
].
map
do
|
entry
|
references
[
:user
].
uniq
.
map
do
|
project
,
identifier
|
if
entry
[
:id
]
==
"all"
if
identifier
==
"all"
project
.
team
.
members
.
flatten
project
.
team
.
members
.
flatten
elsif
namespace
=
Namespace
.
find_by
(
path:
entry
[
:id
]
)
elsif
namespace
=
Namespace
.
find_by
(
path:
identifier
)
if
namespace
.
is_a?
(
Group
)
if
namespace
.
is_a?
(
Group
)
namespace
.
users
namespace
.
users
else
else
namespace
.
owner
namespace
.
owner
end
end
end
end
end
.
flatten
.
compact
end
.
flatten
.
compact
.
uniq
end
end
def
labels
def
labels
references
[
:label
s
].
map
do
|
entry
|
references
[
:label
].
uniq
.
map
do
|
project
,
identifier
|
project
.
labels
.
where
(
id:
entry
[
:id
]
).
first
project
.
labels
.
where
(
id:
identifier
).
first
end
.
compact
end
.
compact
.
uniq
end
end
def
issues
def
issues
references
[
:issue
s
].
map
do
|
entry
|
references
[
:issue
].
uniq
.
map
do
|
project
,
identifier
|
if
entry
[
:project
]
.
default_issues_tracker?
if
project
.
default_issues_tracker?
entry
[
:project
].
issues
.
where
(
iid:
entry
[
:id
]
).
first
project
.
issues
.
where
(
iid:
identifier
).
first
end
end
end
.
compact
end
.
compact
.
uniq
end
end
def
merge_requests
def
merge_requests
references
[
:merge_request
s
].
map
do
|
entry
|
references
[
:merge_request
].
uniq
.
map
do
|
project
,
identifier
|
entry
[
:project
].
merge_requests
.
where
(
iid:
entry
[
:id
]
).
first
project
.
merge_requests
.
where
(
iid:
identifier
).
first
end
.
compact
end
.
compact
.
uniq
end
end
def
snippets
def
snippets
references
[
:snippet
s
].
map
do
|
entry
|
references
[
:snippet
].
uniq
.
map
do
|
project
,
identifier
|
project
.
snippets
.
where
(
id:
entry
[
:id
]
).
first
project
.
snippets
.
where
(
id:
identifier
).
first
end
.
compact
end
.
compact
.
uniq
end
end
def
commits
def
commits
references
[
:commit
s
].
map
do
|
entry
|
references
[
:commit
].
uniq
.
map
do
|
project
,
identifier
|
repo
=
entry
[
:project
]
.
repository
repo
=
project
.
repository
repo
.
commit
(
entry
[
:id
]
)
if
repo
repo
.
commit
(
identifier
)
if
repo
end
.
compact
end
.
compact
.
uniq
end
end
def
commit_ranges
def
commit_ranges
references
[
:commit_range
s
].
map
do
|
entry
|
references
[
:commit_range
].
uniq
.
map
do
|
project
,
identifier
|
repo
=
entry
[
:project
].
repository
if
entry
[
:project
]
repo
=
project
.
repository
if
repo
if
repo
from_id
,
to_id
=
entry
[
:id
]
.
split
(
/\.{2,3}/
,
2
)
from_id
,
to_id
=
identifier
.
split
(
/\.{2,3}/
,
2
)
[
repo
.
commit
(
from_id
),
repo
.
commit
(
to_id
)]
[
repo
.
commit
(
from_id
),
repo
.
commit
(
to_id
)]
end
end
end
.
compact
end
.
compact
.
uniq
end
end
private
private
def
reference_link
(
type
,
identifier
,
project
,
user
,
_
)
def
reference_link
(
type
,
identifier
,
project
,
_
)
references
[
type
]
<<
{
project:
project
,
id:
identifier
}
references
[
type
]
<<
[
project
,
identifier
]
end
end
end
end
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