2016-08-09 17:26:45 +00:00
|
|
|
module Notes
|
|
|
|
class SlashCommandsService < BaseService
|
|
|
|
|
|
|
|
UPDATE_SERVICES = {
|
|
|
|
'Issue' => Issues::UpdateService,
|
|
|
|
'MergeRequest' => MergeRequests::UpdateService
|
|
|
|
}
|
|
|
|
|
2016-08-12 09:19:29 +00:00
|
|
|
def extract_commands(note)
|
|
|
|
@noteable_update_service = UPDATE_SERVICES[note.noteable_type]
|
|
|
|
return [] unless @noteable_update_service
|
|
|
|
return [] unless can?(current_user, :"update_#{note.noteable_type.underscore}", note.noteable)
|
2016-08-09 17:26:45 +00:00
|
|
|
|
2016-08-12 09:19:29 +00:00
|
|
|
SlashCommands::InterpretService.new(project, current_user).
|
2016-08-09 17:26:45 +00:00
|
|
|
execute(note.note, note.noteable)
|
2016-08-12 09:19:29 +00:00
|
|
|
end
|
2016-08-09 17:26:45 +00:00
|
|
|
|
2016-08-12 09:19:29 +00:00
|
|
|
def execute(commands, note)
|
2016-08-09 17:26:45 +00:00
|
|
|
if commands.any?
|
2016-08-12 09:19:29 +00:00
|
|
|
@noteable_update_service.new(project, current_user, commands).
|
|
|
|
execute(note.noteable)
|
2016-08-09 17:26:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|