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