2018-07-17 16:50:37 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-09 17:26:45 +00:00
|
|
|
module Notes
|
2017-05-31 05:50:53 +00:00
|
|
|
class QuickActionsService < BaseService
|
2016-08-09 17:26:45 +00:00
|
|
|
UPDATE_SERVICES = {
|
|
|
|
'Issue' => Issues::UpdateService,
|
2018-07-21 08:52:07 +00:00
|
|
|
'MergeRequest' => MergeRequests::UpdateService,
|
2018-07-23 20:01:23 +00:00
|
|
|
'Commit' => Commits::TagService
|
2017-02-21 23:32:18 +00:00
|
|
|
}.freeze
|
2016-08-09 17:26:45 +00:00
|
|
|
|
2016-09-15 14:57:06 +00:00
|
|
|
def self.noteable_update_service(note)
|
|
|
|
UPDATE_SERVICES[note.noteable_type]
|
|
|
|
end
|
|
|
|
|
2018-03-02 12:03:03 +00:00
|
|
|
def self.supported?(note)
|
|
|
|
!!noteable_update_service(note)
|
2016-09-15 14:57:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def supported?(note)
|
2018-03-02 12:03:03 +00:00
|
|
|
self.class.supported?(note)
|
2016-08-13 16:58:51 +00:00
|
|
|
end
|
|
|
|
|
2016-11-24 14:05:15 +00:00
|
|
|
def extract_commands(note, options = {})
|
2016-08-13 16:58:51 +00:00
|
|
|
return [note.note, {}] unless supported?(note)
|
2016-08-09 17:26:45 +00:00
|
|
|
|
2017-06-21 13:48:12 +00:00
|
|
|
QuickActions::InterpretService.new(project, current_user, options)
|
|
|
|
.execute(note.note, note.noteable)
|
2016-08-12 09:19:29 +00:00
|
|
|
end
|
2016-08-09 17:26:45 +00:00
|
|
|
|
2016-08-13 01:17:18 +00:00
|
|
|
def execute(command_params, note)
|
|
|
|
return if command_params.empty?
|
2016-08-13 16:58:51 +00:00
|
|
|
return unless supported?(note)
|
|
|
|
|
2016-09-15 14:57:06 +00:00
|
|
|
self.class.noteable_update_service(note).new(project, current_user, command_params).execute(note.noteable)
|
2016-08-09 17:26:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|