diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-25 09:09:10 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-25 09:09:10 +0000 |
commit | b98fa9ef3d5bead417ae2f325cb64637883264e9 (patch) | |
tree | 409f2002dd056f12d82d3959b3e6f012c4087123 /lib/gitlab/quick_actions/extractor.rb | |
parent | 7e3005967df23a957fe1998c8de4f50b412e69e7 (diff) | |
download | gitlab-ce-b98fa9ef3d5bead417ae2f325cb64637883264e9.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/quick_actions/extractor.rb')
-rw-r--r-- | lib/gitlab/quick_actions/extractor.rb | 28 |
1 files changed, 16 insertions, 12 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] |