summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-05-14 16:59:39 -0400
committerRobert Speicher <rspeicher@gmail.com>2015-05-26 15:48:32 -0400
commitb88da58cb6272a86b6df2e4efe392f10e689a6b2 (patch)
tree1271524cfe6fa5d733cc847c72b96a19810d06aa /lib
parent94af050117df20a661e03055a5002cae90282d6d (diff)
downloadgitlab-ce-b88da58cb6272a86b6df2e4efe392f10e689a6b2.tar.gz
Add `reference_pattern` to Referable models
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/markdown/commit_range_reference_filter.rb9
-rw-r--r--lib/gitlab/markdown/commit_reference_filter.rb11
-rw-r--r--lib/gitlab/markdown/cross_project_reference.rb3
-rw-r--r--lib/gitlab/markdown/external_issue_reference_filter.rb7
-rw-r--r--lib/gitlab/markdown/issue_reference_filter.rb9
-rw-r--r--lib/gitlab/markdown/label_reference_filter.rb17
-rw-r--r--lib/gitlab/markdown/merge_request_reference_filter.rb9
-rw-r--r--lib/gitlab/markdown/snippet_reference_filter.rb9
-rw-r--r--lib/gitlab/markdown/user_reference_filter.rb7
9 files changed, 16 insertions, 65 deletions
diff --git a/lib/gitlab/markdown/commit_range_reference_filter.rb b/lib/gitlab/markdown/commit_range_reference_filter.rb
index 8764f7e474f..61591a9914b 100644
--- a/lib/gitlab/markdown/commit_range_reference_filter.rb
+++ b/lib/gitlab/markdown/commit_range_reference_filter.rb
@@ -19,7 +19,7 @@ module Gitlab
#
# Returns a String replaced with the return of the block.
def self.references_in(text)
- text.gsub(COMMIT_RANGE_PATTERN) do |match|
+ text.gsub(CommitRange.reference_pattern) do |match|
yield match, $~[:commit_range], $~[:project]
end
end
@@ -30,13 +30,8 @@ module Gitlab
@commit_map = {}
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
- replace_text_nodes_matching(COMMIT_RANGE_PATTERN) do |content|
+ replace_text_nodes_matching(CommitRange.reference_pattern) do |content|
commit_range_link_filter(content)
end
end
diff --git a/lib/gitlab/markdown/commit_reference_filter.rb b/lib/gitlab/markdown/commit_reference_filter.rb
index b20b29f5d0c..f6932e76e70 100644
--- a/lib/gitlab/markdown/commit_reference_filter.rb
+++ b/lib/gitlab/markdown/commit_reference_filter.rb
@@ -19,20 +19,13 @@ module Gitlab
#
# Returns a String replaced with the return of the block.
def self.references_in(text)
- text.gsub(COMMIT_PATTERN) do |match|
+ text.gsub(Commit.reference_pattern) do |match|
yield match, $~[:commit], $~[:project]
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
- replace_text_nodes_matching(COMMIT_PATTERN) do |content|
+ replace_text_nodes_matching(Commit.reference_pattern) do |content|
commit_link_filter(content)
end
end
diff --git a/lib/gitlab/markdown/cross_project_reference.rb b/lib/gitlab/markdown/cross_project_reference.rb
index c436fabd658..66c256c5104 100644
--- a/lib/gitlab/markdown/cross_project_reference.rb
+++ b/lib/gitlab/markdown/cross_project_reference.rb
@@ -3,9 +3,6 @@ module Gitlab
# Common methods for ReferenceFilters that support an optional cross-project
# reference.
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
#
# Defaults to value of `context[:project]` if:
diff --git a/lib/gitlab/markdown/external_issue_reference_filter.rb b/lib/gitlab/markdown/external_issue_reference_filter.rb
index 0fc3f4cca06..2e74c6e45e2 100644
--- a/lib/gitlab/markdown/external_issue_reference_filter.rb
+++ b/lib/gitlab/markdown/external_issue_reference_filter.rb
@@ -16,19 +16,16 @@ module Gitlab
#
# Returns a String replaced with the return of the block.
def self.references_in(text)
- text.gsub(ISSUE_PATTERN) do |match|
+ text.gsub(ExternalIssue.reference_pattern) do |match|
yield match, $~[:issue]
end
end
- # Pattern used to extract `JIRA-123` issue references from text
- ISSUE_PATTERN = /(?<issue>([A-Z\-]+-)\d+)/
-
def call
# Early return if the project isn't using an external 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)
end
end
diff --git a/lib/gitlab/markdown/issue_reference_filter.rb b/lib/gitlab/markdown/issue_reference_filter.rb
index 1e885615163..2815626e247 100644
--- a/lib/gitlab/markdown/issue_reference_filter.rb
+++ b/lib/gitlab/markdown/issue_reference_filter.rb
@@ -20,18 +20,13 @@ module Gitlab
#
# Returns a String replaced with the return of the block.
def self.references_in(text)
- text.gsub(ISSUE_PATTERN) do |match|
+ text.gsub(Issue.reference_pattern) do |match|
yield match, $~[:issue].to_i, $~[:project]
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
- replace_text_nodes_matching(ISSUE_PATTERN) do |content|
+ replace_text_nodes_matching(Issue.reference_pattern) do |content|
issue_link_filter(content)
end
end
diff --git a/lib/gitlab/markdown/label_reference_filter.rb b/lib/gitlab/markdown/label_reference_filter.rb
index 1a77becee89..9f8c85b7012 100644
--- a/lib/gitlab/markdown/label_reference_filter.rb
+++ b/lib/gitlab/markdown/label_reference_filter.rb
@@ -15,26 +15,13 @@ module Gitlab
#
# Returns a String replaced with the return of the block.
def self.references_in(text)
- text.gsub(LABEL_PATTERN) do |match|
+ text.gsub(Label.reference_pattern) do |match|
yield match, $~[:label_id].to_i, $~[:label_name]
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
- replace_text_nodes_matching(LABEL_PATTERN) do |content|
+ replace_text_nodes_matching(Label.reference_pattern) do |content|
label_link_filter(content)
end
end
diff --git a/lib/gitlab/markdown/merge_request_reference_filter.rb b/lib/gitlab/markdown/merge_request_reference_filter.rb
index 740d72abb36..fddc050635f 100644
--- a/lib/gitlab/markdown/merge_request_reference_filter.rb
+++ b/lib/gitlab/markdown/merge_request_reference_filter.rb
@@ -20,18 +20,13 @@ module Gitlab
#
# Returns a String replaced with the return of the block.
def self.references_in(text)
- text.gsub(MERGE_REQUEST_PATTERN) do |match|
+ text.gsub(MergeRequest.reference_pattern) do |match|
yield match, $~[:merge_request].to_i, $~[:project]
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
- replace_text_nodes_matching(MERGE_REQUEST_PATTERN) do |content|
+ replace_text_nodes_matching(MergeRequest.reference_pattern) do |content|
merge_request_link_filter(content)
end
end
diff --git a/lib/gitlab/markdown/snippet_reference_filter.rb b/lib/gitlab/markdown/snippet_reference_filter.rb
index 64a0a2696f7..f22f08de27c 100644
--- a/lib/gitlab/markdown/snippet_reference_filter.rb
+++ b/lib/gitlab/markdown/snippet_reference_filter.rb
@@ -20,18 +20,13 @@ module Gitlab
#
# Returns a String replaced with the return of the block.
def self.references_in(text)
- text.gsub(SNIPPET_PATTERN) do |match|
+ text.gsub(Snippet.reference_pattern) do |match|
yield match, $~[:snippet].to_i, $~[:project]
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
- replace_text_nodes_matching(SNIPPET_PATTERN) do |content|
+ replace_text_nodes_matching(Snippet.reference_pattern) do |content|
snippet_link_filter(content)
end
end
diff --git a/lib/gitlab/markdown/user_reference_filter.rb b/lib/gitlab/markdown/user_reference_filter.rb
index 28ec041b1d4..ca7fd7b0338 100644
--- a/lib/gitlab/markdown/user_reference_filter.rb
+++ b/lib/gitlab/markdown/user_reference_filter.rb
@@ -16,16 +16,13 @@ module Gitlab
#
# Returns a String replaced with the return of the block.
def self.references_in(text)
- text.gsub(USER_PATTERN) do |match|
+ text.gsub(User.reference_pattern) do |match|
yield match, $~[:user]
end
end
- # Pattern used to extract `@user` user references from text
- USER_PATTERN = /@(?<user>#{Gitlab::Regex::NAMESPACE_REGEX_STR})/
-
def call
- replace_text_nodes_matching(USER_PATTERN) do |content|
+ replace_text_nodes_matching(User.reference_pattern) do |content|
user_link_filter(content)
end
end