| ... | ... | @@ -17,16 +17,8 @@ module Notes |
|
|
|
# We execute commands (extracted from `params[:note]`) on the noteable
|
|
|
|
# **before** we save the note because if the note consists of commands
|
|
|
|
# only, there is no need be create a note!
|
|
|
|
quick_actions_service = QuickActionsService.new(project, current_user)
|
|
|
|
|
|
|
|
if quick_actions_service.supported?(note)
|
|
|
|
content, update_params, message = quick_actions_service.execute(note, quick_action_options)
|
|
|
|
|
|
|
|
only_commands = content.empty?
|
|
|
|
|
|
|
|
note.note = content
|
|
|
|
end
|
|
|
|
|
|
|
|
execute_quick_actions(note) do |only_commands|
|
|
|
|
note.run_after_commit do
|
|
|
|
# Finish the harder work in the background
|
|
|
|
NewNoteWorker.perform_async(note.id)
|
| ... | ... | @@ -36,7 +28,31 @@ module Notes |
|
|
|
!only_commands && note.save
|
|
|
|
end
|
|
|
|
|
|
|
|
if note_saved
|
|
|
|
when_saved(note) if note_saved
|
|
|
|
end
|
|
|
|
|
|
|
|
note
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def execute_quick_actions(note)
|
|
|
|
return yield(false) unless quick_actions_service.supported?(note)
|
|
|
|
|
|
|
|
content, update_params, message = quick_actions_service.execute(note, quick_action_options)
|
|
|
|
only_commands = content.empty?
|
|
|
|
note.note = content
|
|
|
|
|
|
|
|
yield(only_commands)
|
|
|
|
|
|
|
|
do_commands(note, update_params, message, only_commands)
|
|
|
|
end
|
|
|
|
|
|
|
|
def quick_actions_service
|
|
|
|
@quick_actions_service ||= QuickActionsService.new(project, current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def when_saved(note)
|
|
|
|
if note.part_of_discussion? && note.discussion.can_convert_to_discussion?
|
|
|
|
note.discussion.convert_to_discussion!(save: true)
|
|
|
|
end
|
| ... | ... | @@ -51,7 +67,9 @@ module Notes |
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if quick_actions_service.commands_executed_count.to_i > 0
|
|
|
|
def do_commands(note, update_params, message, only_commands)
|
|
|
|
return if quick_actions_service.commands_executed_count.to_i.zero?
|
|
|
|
|
|
|
|
if update_params.present?
|
|
|
|
quick_actions_service.apply_updates(update_params, note)
|
|
|
|
note.commands_changes = update_params
|
| ... | ... | @@ -61,14 +79,11 @@ module Notes |
|
|
|
# when #save is called
|
|
|
|
if only_commands
|
|
|
|
note.errors.add(:commands_only, message.presence || _('Failed to apply commands.'))
|
|
|
|
# Allow consumers to detect problems applying commands
|
|
|
|
note.errors.add(:commands, _('Failed to apply commands.')) unless message.present?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
note
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# EE::Notes::CreateService would override this method
|
|
|
|
def quick_action_options
|
|
|
|
{ merge_request_diff_head_sha: params[:merge_request_diff_head_sha] }
|
| ... | ... | |
| ... | ... | |