2018-11-19 21:01:13 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-24 23:11:22 -04:00
|
|
|
module Gitlab
|
|
|
|
module QuickActions
|
|
|
|
class SubstitutionDefinition < CommandDefinition
|
|
|
|
# noop?=>true means these won't get extracted or removed by Gitlab::QuickActions::Extractor#extract_commands
|
|
|
|
# QuickActions::InterpretService#perform_substitutions handles them separately
|
|
|
|
def noop?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def match(content)
|
2020-02-13 07:08:49 -05:00
|
|
|
content.match %r{^/#{all_names.join('|')}(?![\S]) ?(.*)$}
|
2017-07-24 23:11:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def perform_substitution(context, content)
|
|
|
|
return unless content
|
|
|
|
|
|
|
|
all_names.each do |a_name|
|
2020-02-25 04:09:10 -05:00
|
|
|
content = content.sub(%r{/#{a_name}(?![\S]) ?(.*)$}i, execute_block(action_block, context, '\1'))
|
2017-07-24 23:11:22 -04:00
|
|
|
end
|
2019-08-22 20:52:35 -04:00
|
|
|
|
2017-07-24 23:11:22 -04:00
|
|
|
content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|