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
Tatuya Kamada
gitlab-ce
Commits
43c62ca3
Commit
43c62ca3
authored
Apr 13, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove Gitlab::Markdown from Gitlab::ReferenceExtractor
parent
29604ff2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
2 deletions
+66
-2
lib/gitlab/reference_extractor.rb
lib/gitlab/reference_extractor.rb
+66
-2
No files found.
lib/gitlab/reference_extractor.rb
View file @
43c62ca3
...
@@ -3,8 +3,6 @@ module Gitlab
...
@@ -3,8 +3,6 @@ module Gitlab
class
ReferenceExtractor
class
ReferenceExtractor
attr_accessor
:project
,
:current_user
,
:references
attr_accessor
:project
,
:current_user
,
:references
include
::
Gitlab
::
Markdown
def
initialize
(
project
,
current_user
=
nil
)
def
initialize
(
project
,
current_user
=
nil
)
@project
=
project
@project
=
project
@current_user
=
current_user
@current_user
=
current_user
...
@@ -87,6 +85,72 @@ module Gitlab
...
@@ -87,6 +85,72 @@ module Gitlab
private
private
NAME_STR
=
Gitlab
::
Regex
::
NAMESPACE_REGEX_STR
PROJ_STR
=
"(?<project>
#{
NAME_STR
}
/
#{
NAME_STR
}
)"
REFERENCE_PATTERN
=
%r{
(?<prefix>
\W
)? # Prefix
( # Reference
@(?<user>
#{
NAME_STR
}
) # User name
|~(?<label>
\d
+) # Label ID
|(?<issue>([A-Z
\-
]+-)
\d
+) # JIRA Issue ID
|
#{
PROJ_STR
}
?
\#
(?<issue>([a-zA-Z
\-
]+-)?
\d
+) # Issue ID
|
#{
PROJ_STR
}
?!(?<merge_request>
\d
+) # MR ID
|
\$
(?<snippet>
\d
+) # Snippet ID
|(
#{
PROJ_STR
}
@)?(?<commit_range>[
\h
]{6,40}
\.
{2,3}[
\h
]{6,40}) # Commit range
|(
#{
PROJ_STR
}
@)?(?<commit>[
\h
]{6,40}) # Commit ID
)
(?<suffix>
\W
)? # Suffix
}x
.
freeze
TYPES
=
%i(user issue label merge_request snippet commit commit_range)
.
freeze
def
parse_references
(
text
,
project
=
@project
)
# parse reference links
text
.
gsub!
(
REFERENCE_PATTERN
)
do
|
match
|
type
=
TYPES
.
detect
{
|
t
|
$~
[
t
].
present?
}
actual_project
=
project
project_prefix
=
nil
project_path
=
$LAST_MATCH_INFO
[
:project
]
if
project_path
actual_project
=
::
Project
.
find_with_namespace
(
project_path
)
actual_project
=
nil
unless
can?
(
current_user
,
:read_project
,
actual_project
)
project_prefix
=
project_path
end
parse_result
(
$LAST_MATCH_INFO
,
type
,
actual_project
,
project_prefix
)
||
match
end
end
# Called from #parse_references. Attempts to build a gitlab reference
# link. Returns nil if +type+ is nil, if the match string is an HTML
# entity, if the reference is invalid, or if the matched text includes an
# invalid project path.
def
parse_result
(
match_info
,
type
,
project
,
project_prefix
)
prefix
=
match_info
[
:prefix
]
suffix
=
match_info
[
:suffix
]
return
nil
if
html_entity?
(
prefix
,
suffix
)
||
type
.
nil?
return
nil
if
project
.
nil?
&&
!
project_prefix
.
nil?
identifier
=
match_info
[
type
]
ref_link
=
reference_link
(
type
,
identifier
,
project
,
project_prefix
)
if
ref_link
"
#{
prefix
}#{
ref_link
}#{
suffix
}
"
else
nil
end
end
# Return true if the +prefix+ and +suffix+ indicate that the matched string
# is an HTML entity like &
def
html_entity?
(
prefix
,
suffix
)
prefix
&&
suffix
&&
prefix
[
0
]
==
'&'
&&
suffix
[
-
1
]
==
';'
end
def
reference_link
(
type
,
identifier
,
project
,
_
)
def
reference_link
(
type
,
identifier
,
project
,
_
)
references
[
type
]
<<
[
project
,
identifier
]
references
[
type
]
<<
[
project
,
identifier
]
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