diff options
Diffstat (limited to 'lib/gitlab/email/handler/reply_processing.rb')
-rw-r--r-- | lib/gitlab/email/handler/reply_processing.rb | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/lib/gitlab/email/handler/reply_processing.rb b/lib/gitlab/email/handler/reply_processing.rb index d508cf9360e..a717509e24d 100644 --- a/lib/gitlab/email/handler/reply_processing.rb +++ b/lib/gitlab/email/handler/reply_processing.rb @@ -35,13 +35,20 @@ module Gitlab @message_with_reply ||= process_message(trim_reply: false) end + def message_with_appended_reply + @message_with_appended_reply ||= process_message(append_reply: true) + end + def process_message(**kwargs) - message = ReplyParser.new(mail, **kwargs).execute.strip + message, stripped_text = ReplyParser.new(mail, **kwargs).execute + message = message.strip + message_with_attachments = add_attachments(message) + # Support bot is specifically forbidden from using slash commands. + message = strip_quick_actions(message_with_attachments) + return message unless kwargs[:append_reply] - # Support bot is specifically forbidden - # from using slash commands. - strip_quick_actions(message_with_attachments) + append_reply(message, stripped_text) end def add_attachments(reply) @@ -92,10 +99,22 @@ module Gitlab def strip_quick_actions(content) return content unless author.support_bot? + quick_actions_extractor.redact_commands(content) + end + + def quick_actions_extractor command_definitions = ::QuickActions::InterpretService.command_definitions - extractor = ::Gitlab::QuickActions::Extractor.new(command_definitions) + ::Gitlab::QuickActions::Extractor.new(command_definitions) + end + + def append_reply(message, reply) + return message if message.blank? || reply.blank? + + # Do not append if message only contains slash commands + body, _commands = quick_actions_extractor.extract_commands(message) + return message if body.empty? - extractor.redact_commands(content) + message + "\n\n<details><summary>...</summary>\n\n#{reply}\n\n</details>" end end end |