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
b88da58c
Commit
b88da58c
authored
May 14, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `reference_pattern` to Referable models
parent
94af0501
Changes
20
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
130 additions
and
74 deletions
+130
-74
app/models/commit.rb
app/models/commit.rb
+13
-0
app/models/commit_range.rb
app/models/commit_range.rb
+16
-2
app/models/concerns/referable.rb
app/models/concerns/referable.rb
+10
-0
app/models/external_issue.rb
app/models/external_issue.rb
+9
-4
app/models/group.rb
app/models/group.rb
+5
-1
app/models/issue.rb
app/models/issue.rb
+12
-2
app/models/label.rb
app/models/label.rb
+16
-0
app/models/merge_request.rb
app/models/merge_request.rb
+10
-0
app/models/project.rb
app/models/project.rb
+5
-0
app/models/snippet.rb
app/models/snippet.rb
+10
-0
app/models/user.rb
app/models/user.rb
+8
-0
lib/gitlab/markdown/commit_range_reference_filter.rb
lib/gitlab/markdown/commit_range_reference_filter.rb
+2
-7
lib/gitlab/markdown/commit_reference_filter.rb
lib/gitlab/markdown/commit_reference_filter.rb
+2
-9
lib/gitlab/markdown/cross_project_reference.rb
lib/gitlab/markdown/cross_project_reference.rb
+0
-3
lib/gitlab/markdown/external_issue_reference_filter.rb
lib/gitlab/markdown/external_issue_reference_filter.rb
+2
-5
lib/gitlab/markdown/issue_reference_filter.rb
lib/gitlab/markdown/issue_reference_filter.rb
+2
-7
lib/gitlab/markdown/label_reference_filter.rb
lib/gitlab/markdown/label_reference_filter.rb
+2
-15
lib/gitlab/markdown/merge_request_reference_filter.rb
lib/gitlab/markdown/merge_request_reference_filter.rb
+2
-7
lib/gitlab/markdown/snippet_reference_filter.rb
lib/gitlab/markdown/snippet_reference_filter.rb
+2
-7
lib/gitlab/markdown/user_reference_filter.rb
lib/gitlab/markdown/user_reference_filter.rb
+2
-5
No files found.
app/models/commit.rb
View file @
b88da58c
...
@@ -62,6 +62,19 @@ class Commit
...
@@ -62,6 +62,19 @@ class Commit
(
self
.
class
===
other
)
&&
(
raw
==
other
.
raw
)
(
self
.
class
===
other
)
&&
(
raw
==
other
.
raw
)
end
end
def
self
.
reference_prefix
'@'
end
# Pattern used to extract commit references from text
#
# The SHA can be between 6 and 40 hex characters.
#
# This pattern supports cross-project references.
def
self
.
reference_pattern
%r{(?:
#{
Project
.
reference_pattern
}#{
reference_prefix
}
)?(?<commit>
\h
{6,40})}
end
def
to_reference
(
from_project
=
nil
)
def
to_reference
(
from_project
=
nil
)
if
cross_project_reference?
(
from_project
)
if
cross_project_reference?
(
from_project
)
"
#{
project
.
to_reference
}
@
#{
id
}
"
"
#{
project
.
to_reference
}
@
#{
id
}
"
...
...
app/models/commit_range.rb
View file @
b88da58c
...
@@ -29,10 +29,24 @@ class CommitRange
...
@@ -29,10 +29,24 @@ class CommitRange
# See `exclude_start?`
# See `exclude_start?`
attr_reader
:exclude_start
attr_reader
:exclude_start
# The beginning and ending SHA
sums can be between 6 and 40 hex characters,
# The beginning and ending SHA
s can be between 6 and 40 hex characters, and
#
and the range selec
tion can be double- or triple-dot.
#
the range nota
tion can be double- or triple-dot.
PATTERN
=
/\h{6,40}\.{2,3}\h{6,40}/
PATTERN
=
/\h{6,40}\.{2,3}\h{6,40}/
def
self
.
reference_prefix
'@'
end
# Pattern used to extract commit range references from text
#
# This pattern supports cross-project references.
def
self
.
reference_pattern
%r{
(?:
#{
Project
.
reference_pattern
}#{
reference_prefix
}
)?
(?<commit_range>
#{
PATTERN
}
)
}x
end
# Initialize a CommitRange
# Initialize a CommitRange
#
#
# range_string - The String commit range.
# range_string - The String commit range.
...
...
app/models/concerns/referable.rb
View file @
b88da58c
...
@@ -35,6 +35,16 @@ module Referable
...
@@ -35,6 +35,16 @@ module Referable
def
reference_prefix
def
reference_prefix
''
''
end
end
# Regexp pattern used to match references to this object
#
# This must be overridden by the including class.
#
# Returns Regexp
def
reference_pattern
raise
NotImplementedError
,
%Q{
#{
self
}
does not implement "reference_pattern"}
end
end
end
private
private
...
...
app/models/external_issue.rb
View file @
b88da58c
...
@@ -9,10 +9,6 @@ class ExternalIssue
...
@@ -9,10 +9,6 @@ class ExternalIssue
@issue_identifier
.
to_s
@issue_identifier
.
to_s
end
end
def
to_reference
(
_from_project
=
nil
)
id
end
def
id
def
id
@issue_identifier
.
to_s
@issue_identifier
.
to_s
end
end
...
@@ -32,4 +28,13 @@ class ExternalIssue
...
@@ -32,4 +28,13 @@ class ExternalIssue
def
project
def
project
@project
@project
end
end
# Pattern used to extract `JIRA-123` issue references from text
def
self
.
reference_pattern
%r{(?<issue>([A-Z
\-
]+-)
\d
+)}
end
def
to_reference
(
_from_project
=
nil
)
id
end
end
end
app/models/group.rb
View file @
b88da58c
...
@@ -40,7 +40,11 @@ class Group < Namespace
...
@@ -40,7 +40,11 @@ class Group < Namespace
end
end
def
reference_prefix
def
reference_prefix
'@'
User
.
reference_prefix
end
def
reference_pattern
User
.
reference_pattern
end
end
end
end
...
...
app/models/issue.rb
View file @
b88da58c
...
@@ -50,12 +50,22 @@ class Issue < ActiveRecord::Base
...
@@ -50,12 +50,22 @@ class Issue < ActiveRecord::Base
state
:closed
state
:closed
end
end
def
hook_attrs
attributes
end
def
self
.
reference_prefix
def
self
.
reference_prefix
'#'
'#'
end
end
def
hook_attrs
# Pattern used to extract `#123` issue references from text
attributes
#
# This pattern supports cross-project references.
def
self
.
reference_pattern
%r{
#{
Project
.
reference_pattern
}
?
#{
Regexp
.
escape
(
reference_prefix
)
}
(?<issue>
\d
+)
}x
end
end
def
to_reference
(
from_project
=
nil
)
def
to_reference
(
from_project
=
nil
)
...
...
app/models/label.rb
View file @
b88da58c
...
@@ -40,6 +40,22 @@ class Label < ActiveRecord::Base
...
@@ -40,6 +40,22 @@ class Label < ActiveRecord::Base
'~'
'~'
end
end
# Pattern used to extract label references from text
#
# TODO (rspeicher): Limit to double quotes (meh) or disallow single quotes in label names (bad).
def
self
.
reference_pattern
%r{
#{
reference_prefix
}
(?:
(?<label_id>
\d
+) | # Integer-based label ID, or
(?<label_name>
[A-Za-z0-9_-]+ | # String-based single-word label title
['"][^&
\?
,]+['"] # String-based multi-word label surrounded in quotes
)
)
}x
end
# Returns the String necessary to reference this Label in Markdown
# Returns the String necessary to reference this Label in Markdown
#
#
# format - Symbol format to use (default: :id, optional: :name)
# format - Symbol format to use (default: :id, optional: :name)
...
...
app/models/merge_request.rb
View file @
b88da58c
...
@@ -140,6 +140,16 @@ class MergeRequest < ActiveRecord::Base
...
@@ -140,6 +140,16 @@ class MergeRequest < ActiveRecord::Base
'!'
'!'
end
end
# Pattern used to extract `!123` merge request references from text
#
# This pattern supports cross-project references.
def
self
.
reference_pattern
%r{
#{
Project
.
reference_pattern
}
?
#{
Regexp
.
escape
(
reference_prefix
)
}
(?<merge_request>
\d
+)
}x
end
def
to_reference
(
from_project
=
nil
)
def
to_reference
(
from_project
=
nil
)
reference
=
"
#{
self
.
class
.
reference_prefix
}#{
iid
}
"
reference
=
"
#{
self
.
class
.
reference_prefix
}#{
iid
}
"
...
...
app/models/project.rb
View file @
b88da58c
...
@@ -248,6 +248,11 @@ class Project < ActiveRecord::Base
...
@@ -248,6 +248,11 @@ class Project < ActiveRecord::Base
order_by
(
method
)
order_by
(
method
)
end
end
end
end
def
reference_pattern
name_pattern
=
Gitlab
::
Regex
::
NAMESPACE_REGEX_STR
%r{(?<project>
#{
name_pattern
}
/
#{
name_pattern
}
)}
end
end
end
def
team
def
team
...
...
app/models/snippet.rb
View file @
b88da58c
...
@@ -56,6 +56,16 @@ class Snippet < ActiveRecord::Base
...
@@ -56,6 +56,16 @@ class Snippet < ActiveRecord::Base
'$'
'$'
end
end
# Pattern used to extract `$123` snippet references from text
#
# This pattern supports cross-project references.
def
self
.
reference_pattern
%r{
#{
Project
.
reference_pattern
}
?
#{
Regexp
.
escape
(
reference_prefix
)
}
(?<snippet>
\d
+)
}x
end
def
to_reference
(
from_project
=
nil
)
def
to_reference
(
from_project
=
nil
)
reference
=
"
#{
self
.
class
.
reference_prefix
}#{
id
}
"
reference
=
"
#{
self
.
class
.
reference_prefix
}#{
id
}
"
...
...
app/models/user.rb
View file @
b88da58c
...
@@ -253,6 +253,14 @@ class User < ActiveRecord::Base
...
@@ -253,6 +253,14 @@ class User < ActiveRecord::Base
def
reference_prefix
def
reference_prefix
'@'
'@'
end
end
# Pattern used to extract `@user` user references from text
def
reference_pattern
%r{
#{
Regexp
.
escape
(
reference_prefix
)
}
(?<user>
#{
Gitlab
::
Regex
::
NAMESPACE_REGEX_STR
}
)
}x
end
end
end
#
#
...
...
lib/gitlab/markdown/commit_range_reference_filter.rb
View file @
b88da58c
...
@@ -19,7 +19,7 @@ module Gitlab
...
@@ -19,7 +19,7 @@ module Gitlab
#
#
# Returns a String replaced with the return of the block.
# Returns a String replaced with the return of the block.
def
self
.
references_in
(
text
)
def
self
.
references_in
(
text
)
text
.
gsub
(
C
OMMIT_RANGE_PATTERN
)
do
|
match
|
text
.
gsub
(
C
ommitRange
.
reference_pattern
)
do
|
match
|
yield
match
,
$~
[
:commit_range
],
$~
[
:project
]
yield
match
,
$~
[
:commit_range
],
$~
[
:project
]
end
end
end
end
...
@@ -30,13 +30,8 @@ module Gitlab
...
@@ -30,13 +30,8 @@ module Gitlab
@commit_map
=
{}
@commit_map
=
{}
end
end
# Pattern used to extract commit range references from text
#
# This pattern supports cross-project references.
COMMIT_RANGE_PATTERN
=
/(
#{
PROJECT_PATTERN
}
@)?(?<commit_range>
#{
CommitRange
::
PATTERN
}
)/
def
call
def
call
replace_text_nodes_matching
(
C
OMMIT_RANGE_PATTERN
)
do
|
content
|
replace_text_nodes_matching
(
C
ommitRange
.
reference_pattern
)
do
|
content
|
commit_range_link_filter
(
content
)
commit_range_link_filter
(
content
)
end
end
end
end
...
...
lib/gitlab/markdown/commit_reference_filter.rb
View file @
b88da58c
...
@@ -19,20 +19,13 @@ module Gitlab
...
@@ -19,20 +19,13 @@ module Gitlab
#
#
# Returns a String replaced with the return of the block.
# Returns a String replaced with the return of the block.
def
self
.
references_in
(
text
)
def
self
.
references_in
(
text
)
text
.
gsub
(
C
OMMIT_PATTERN
)
do
|
match
|
text
.
gsub
(
C
ommit
.
reference_pattern
)
do
|
match
|
yield
match
,
$~
[
:commit
],
$~
[
:project
]
yield
match
,
$~
[
:commit
],
$~
[
:project
]
end
end
end
end
# Pattern used to extract commit references from text
#
# The SHA1 sum can be between 6 and 40 hex characters.
#
# This pattern supports cross-project references.
COMMIT_PATTERN
=
/(
#{
PROJECT_PATTERN
}
@)?(?<commit>\h{6,40})/
def
call
def
call
replace_text_nodes_matching
(
C
OMMIT_PATTERN
)
do
|
content
|
replace_text_nodes_matching
(
C
ommit
.
reference_pattern
)
do
|
content
|
commit_link_filter
(
content
)
commit_link_filter
(
content
)
end
end
end
end
...
...
lib/gitlab/markdown/cross_project_reference.rb
View file @
b88da58c
...
@@ -3,9 +3,6 @@ module Gitlab
...
@@ -3,9 +3,6 @@ module Gitlab
# Common methods for ReferenceFilters that support an optional cross-project
# Common methods for ReferenceFilters that support an optional cross-project
# reference.
# reference.
module
CrossProjectReference
module
CrossProjectReference
NAMING_PATTERN
=
Gitlab
::
Regex
::
NAMESPACE_REGEX_STR
PROJECT_PATTERN
=
"(?<project>
#{
NAMING_PATTERN
}
/
#{
NAMING_PATTERN
}
)"
# Given a cross-project reference string, get the Project record
# Given a cross-project reference string, get the Project record
#
#
# Defaults to value of `context[:project]` if:
# Defaults to value of `context[:project]` if:
...
...
lib/gitlab/markdown/external_issue_reference_filter.rb
View file @
b88da58c
...
@@ -16,19 +16,16 @@ module Gitlab
...
@@ -16,19 +16,16 @@ module Gitlab
#
#
# Returns a String replaced with the return of the block.
# Returns a String replaced with the return of the block.
def
self
.
references_in
(
text
)
def
self
.
references_in
(
text
)
text
.
gsub
(
ISSUE_PATTERN
)
do
|
match
|
text
.
gsub
(
ExternalIssue
.
reference_pattern
)
do
|
match
|
yield
match
,
$~
[
:issue
]
yield
match
,
$~
[
:issue
]
end
end
end
end
# Pattern used to extract `JIRA-123` issue references from text
ISSUE_PATTERN
=
/(?<issue>([A-Z\-]+-)\d+)/
def
call
def
call
# Early return if the project isn't using an external tracker
# Early return if the project isn't using an external tracker
return
doc
if
project
.
nil?
||
project
.
default_issues_tracker?
return
doc
if
project
.
nil?
||
project
.
default_issues_tracker?
replace_text_nodes_matching
(
ISSUE_PATTERN
)
do
|
content
|
replace_text_nodes_matching
(
ExternalIssue
.
reference_pattern
)
do
|
content
|
issue_link_filter
(
content
)
issue_link_filter
(
content
)
end
end
end
end
...
...
lib/gitlab/markdown/issue_reference_filter.rb
View file @
b88da58c
...
@@ -20,18 +20,13 @@ module Gitlab
...
@@ -20,18 +20,13 @@ module Gitlab
#
#
# Returns a String replaced with the return of the block.
# Returns a String replaced with the return of the block.
def
self
.
references_in
(
text
)
def
self
.
references_in
(
text
)
text
.
gsub
(
I
SSUE_PATTERN
)
do
|
match
|
text
.
gsub
(
I
ssue
.
reference_pattern
)
do
|
match
|
yield
match
,
$~
[
:issue
].
to_i
,
$~
[
:project
]
yield
match
,
$~
[
:issue
].
to_i
,
$~
[
:project
]
end
end
end
end
# Pattern used to extract `#123` issue references from text
#
# This pattern supports cross-project references.
ISSUE_PATTERN
=
/
#{
PROJECT_PATTERN
}
?\#(?<issue>([a-zA-Z\-]+-)?\d+)/
def
call
def
call
replace_text_nodes_matching
(
I
SSUE_PATTERN
)
do
|
content
|
replace_text_nodes_matching
(
I
ssue
.
reference_pattern
)
do
|
content
|
issue_link_filter
(
content
)
issue_link_filter
(
content
)
end
end
end
end
...
...
lib/gitlab/markdown/label_reference_filter.rb
View file @
b88da58c
...
@@ -15,26 +15,13 @@ module Gitlab
...
@@ -15,26 +15,13 @@ module Gitlab
#
#
# Returns a String replaced with the return of the block.
# Returns a String replaced with the return of the block.
def
self
.
references_in
(
text
)
def
self
.
references_in
(
text
)
text
.
gsub
(
L
ABEL_PATTERN
)
do
|
match
|
text
.
gsub
(
L
abel
.
reference_pattern
)
do
|
match
|
yield
match
,
$~
[
:label_id
].
to_i
,
$~
[
:label_name
]
yield
match
,
$~
[
:label_id
].
to_i
,
$~
[
:label_name
]
end
end
end
end
# Pattern used to extract label references from text
#
# TODO (rspeicher): Limit to double quotes (meh) or disallow single quotes in label names (bad).
LABEL_PATTERN
=
%r{
~(
(?<label_id>
\d
+) | # Integer-based label ID, or
(?<label_name>
[A-Za-z0-9_-]+ | # String-based single-word label title
['"][^&
\?
,]+['"] # String-based multi-word label surrounded in quotes
)
)
}x
def
call
def
call
replace_text_nodes_matching
(
L
ABEL_PATTERN
)
do
|
content
|
replace_text_nodes_matching
(
L
abel
.
reference_pattern
)
do
|
content
|
label_link_filter
(
content
)
label_link_filter
(
content
)
end
end
end
end
...
...
lib/gitlab/markdown/merge_request_reference_filter.rb
View file @
b88da58c
...
@@ -20,18 +20,13 @@ module Gitlab
...
@@ -20,18 +20,13 @@ module Gitlab
#
#
# Returns a String replaced with the return of the block.
# Returns a String replaced with the return of the block.
def
self
.
references_in
(
text
)
def
self
.
references_in
(
text
)
text
.
gsub
(
M
ERGE_REQUEST_PATTERN
)
do
|
match
|
text
.
gsub
(
M
ergeRequest
.
reference_pattern
)
do
|
match
|
yield
match
,
$~
[
:merge_request
].
to_i
,
$~
[
:project
]
yield
match
,
$~
[
:merge_request
].
to_i
,
$~
[
:project
]
end
end
end
end
# Pattern used to extract `!123` merge request references from text
#
# This pattern supports cross-project references.
MERGE_REQUEST_PATTERN
=
/
#{
PROJECT_PATTERN
}
?!(?<merge_request>\d+)/
def
call
def
call
replace_text_nodes_matching
(
M
ERGE_REQUEST_PATTERN
)
do
|
content
|
replace_text_nodes_matching
(
M
ergeRequest
.
reference_pattern
)
do
|
content
|
merge_request_link_filter
(
content
)
merge_request_link_filter
(
content
)
end
end
end
end
...
...
lib/gitlab/markdown/snippet_reference_filter.rb
View file @
b88da58c
...
@@ -20,18 +20,13 @@ module Gitlab
...
@@ -20,18 +20,13 @@ module Gitlab
#
#
# Returns a String replaced with the return of the block.
# Returns a String replaced with the return of the block.
def
self
.
references_in
(
text
)
def
self
.
references_in
(
text
)
text
.
gsub
(
S
NIPPET_PATTERN
)
do
|
match
|
text
.
gsub
(
S
nippet
.
reference_pattern
)
do
|
match
|
yield
match
,
$~
[
:snippet
].
to_i
,
$~
[
:project
]
yield
match
,
$~
[
:snippet
].
to_i
,
$~
[
:project
]
end
end
end
end
# Pattern used to extract `$123` snippet references from text
#
# This pattern supports cross-project references.
SNIPPET_PATTERN
=
/
#{
PROJECT_PATTERN
}
?\$(?<snippet>\d+)/
def
call
def
call
replace_text_nodes_matching
(
S
NIPPET_PATTERN
)
do
|
content
|
replace_text_nodes_matching
(
S
nippet
.
reference_pattern
)
do
|
content
|
snippet_link_filter
(
content
)
snippet_link_filter
(
content
)
end
end
end
end
...
...
lib/gitlab/markdown/user_reference_filter.rb
View file @
b88da58c
...
@@ -16,16 +16,13 @@ module Gitlab
...
@@ -16,16 +16,13 @@ module Gitlab
#
#
# Returns a String replaced with the return of the block.
# Returns a String replaced with the return of the block.
def
self
.
references_in
(
text
)
def
self
.
references_in
(
text
)
text
.
gsub
(
U
SER_PATTERN
)
do
|
match
|
text
.
gsub
(
U
ser
.
reference_pattern
)
do
|
match
|
yield
match
,
$~
[
:user
]
yield
match
,
$~
[
:user
]
end
end
end
end
# Pattern used to extract `@user` user references from text
USER_PATTERN
=
/@(?<user>
#{
Gitlab
::
Regex
::
NAMESPACE_REGEX_STR
}
)/
def
call
def
call
replace_text_nodes_matching
(
U
SER_PATTERN
)
do
|
content
|
replace_text_nodes_matching
(
U
ser
.
reference_pattern
)
do
|
content
|
user_link_filter
(
content
)
user_link_filter
(
content
)
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