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:
Diffstat (limited to 'lib/gitlab/email/handler')
-rw-r--r--lib/gitlab/email/handler/create_note_handler.rb11
-rw-r--r--lib/gitlab/email/handler/reply_processing.rb31
2 files changed, 34 insertions, 8 deletions
diff --git a/lib/gitlab/email/handler/create_note_handler.rb b/lib/gitlab/email/handler/create_note_handler.rb
index 28200643296..4fa2fe1724e 100644
--- a/lib/gitlab/email/handler/create_note_handler.rb
+++ b/lib/gitlab/email/handler/create_note_handler.rb
@@ -5,6 +5,7 @@ require 'gitlab/email/handler/reply_processing'
# handles note/reply creation emails with these formats:
# incoming+1234567890abcdef1234567890abcdef@incoming.gitlab.com
+# Quoted material is _not_ stripped but appended as a `details` section
module Gitlab
module Email
module Handler
@@ -24,7 +25,7 @@ module Gitlab
validate_permission!(:create_note)
raise NoteableNotFoundError unless noteable
- raise EmptyEmailError if message.blank?
+ raise EmptyEmailError if note_message.blank?
verify_record!(
record: create_note,
@@ -47,7 +48,13 @@ module Gitlab
end
def create_note
- sent_notification.create_reply(message)
+ sent_notification.create_reply(note_message)
+ end
+
+ def note_message
+ return message unless sent_notification.noteable_type == "Issue"
+
+ message_with_appended_reply
end
end
end
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