BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
2 deletions
+66
-2
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
class
ReferenceExtractor
attr_accessor
:project
,
:current_user
,
:references
include
::
Gitlab
::
Markdown
def
initialize
(
project
,
current_user
=
nil
)
@project
=
project
@current_user
=
current_user
...
...
@@ -87,6 +85,72 @@ module Gitlab
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
,
_
)
references
[
type
]
<<
[
project
,
identifier
]
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