gitlab-org--gitlab-foss/app/services/notes/quick_actions_service.rb

43 lines
1.0 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
module Notes
class QuickActionsService < BaseService
UPDATE_SERVICES = {
'Issue' => Issues::UpdateService,
'MergeRequest' => MergeRequests::UpdateService,
'Commit' => Commits::TagService
2017-02-21 23:32:18 +00:00
}.freeze
private_constant :UPDATE_SERVICES
def self.update_services
UPDATE_SERVICES
end
def self.noteable_update_service(note)
update_services[note.noteable_type]
end
def self.supported?(note)
!!noteable_update_service(note)
end
def supported?(note)
self.class.supported?(note)
end
2016-11-24 14:05:15 +00:00
def extract_commands(note, options = {})
return [note.note, {}] unless supported?(note)
2017-06-21 13:48:12 +00:00
QuickActions::InterpretService.new(project, current_user, options)
.execute(note.note, note.noteable)
end
2016-08-13 01:17:18 +00:00
def execute(command_params, note)
return if command_params.empty?
return unless supported?(note)
self.class.noteable_update_service(note).new(note.parent, current_user, command_params).execute(note.noteable)
end
end
end