Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-25 12:09:10 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-25 12:09:10 +0300
commitb98fa9ef3d5bead417ae2f325cb64637883264e9 (patch)
tree409f2002dd056f12d82d3959b3e6f012c4087123 /lib/gitlab/quick_actions
parent7e3005967df23a957fe1998c8de4f50b412e69e7 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/quick_actions')
-rw-r--r--lib/gitlab/quick_actions/extractor.rb28
-rw-r--r--lib/gitlab/quick_actions/substitution_definition.rb2
2 files changed, 17 insertions, 13 deletions
diff --git a/lib/gitlab/quick_actions/extractor.rb b/lib/gitlab/quick_actions/extractor.rb
index 6f87968e286..11f5df08e48 100644
--- a/lib/gitlab/quick_actions/extractor.rb
+++ b/lib/gitlab/quick_actions/extractor.rb
@@ -13,6 +13,7 @@ module Gitlab
def initialize(command_definitions)
@command_definitions = command_definitions
+ @commands_regex = {}
end
# Extracts commands from content and return an array of commands.
@@ -58,7 +59,8 @@ module Gitlab
content = content.dup
content.delete!("\r")
- content.gsub!(commands_regex(only: only)) do
+ names = command_names(limit_to_commands: only).map(&:to_s)
+ content.gsub!(commands_regex(names: names)) do
command, output = process_commands($~, redact)
commands << command
output
@@ -91,10 +93,8 @@ module Gitlab
# It looks something like:
#
# /^\/(?<cmd>close|reopen|...)(?:( |$))(?<arg>[^\/\n]*)(?:\n|$)/
- def commands_regex(only:)
- names = command_names(limit_to_commands: only).map(&:to_s)
-
- @commands_regex ||= %r{
+ def commands_regex(names:)
+ @commands_regex[names] ||= %r{
(?<code>
# Code blocks:
# ```
@@ -151,14 +151,18 @@ module Gitlab
end
substitution_definitions.each do |substitution|
- match_data = substitution.match(content.downcase)
- if match_data
- command = [substitution.name.to_s]
- command << match_data[1] unless match_data[1].empty?
- commands << command
+ regex = commands_regex(names: substitution.all_names)
+ content = content.gsub(regex) do |text|
+ if $~[:cmd]
+ command = [substitution.name.to_s]
+ command << $~[:arg] if $~[:arg].present?
+ commands << command
+
+ substitution.perform_substitution(self, text)
+ else
+ text
+ end
end
-
- content = substitution.perform_substitution(self, content)
end
[content, commands]
diff --git a/lib/gitlab/quick_actions/substitution_definition.rb b/lib/gitlab/quick_actions/substitution_definition.rb
index b7231aa3a8b..cd4d202e8d0 100644
--- a/lib/gitlab/quick_actions/substitution_definition.rb
+++ b/lib/gitlab/quick_actions/substitution_definition.rb
@@ -17,7 +17,7 @@ module Gitlab
return unless content
all_names.each do |a_name|
- content = content.gsub(%r{/#{a_name}(?![\S]) ?(.*)$}i, execute_block(action_block, context, '\1'))
+ content = content.sub(%r{/#{a_name}(?![\S]) ?(.*)$}i, execute_block(action_block, context, '\1'))
end
content