2016-11-16 12:28:38 -05:00
|
|
|
module Gitlab
|
2017-05-31 01:50:53 -04:00
|
|
|
module SlashCommands
|
2016-11-16 12:28:38 -05:00
|
|
|
class Command < BaseCommand
|
|
|
|
COMMANDS = [
|
2017-05-31 01:50:53 -04:00
|
|
|
Gitlab::SlashCommands::IssueShow,
|
|
|
|
Gitlab::SlashCommands::IssueNew,
|
|
|
|
Gitlab::SlashCommands::IssueSearch,
|
|
|
|
Gitlab::SlashCommands::Deploy
|
2016-11-16 12:28:38 -05:00
|
|
|
].freeze
|
|
|
|
|
|
|
|
def execute
|
2016-11-17 15:27:12 -05:00
|
|
|
command, match = match_command
|
|
|
|
|
|
|
|
if command
|
|
|
|
if command.allowed?(project, current_user)
|
2017-01-10 13:43:58 -05:00
|
|
|
command.new(project, current_user, params).execute(match)
|
2016-11-17 15:27:12 -05:00
|
|
|
else
|
2017-05-31 01:50:53 -04:00
|
|
|
Gitlab::SlashCommands::Presenters::Access.new.access_denied
|
2016-11-17 15:27:12 -05:00
|
|
|
end
|
2016-11-17 09:30:04 -05:00
|
|
|
else
|
2017-05-31 01:50:53 -04:00
|
|
|
Gitlab::SlashCommands::Help.new(project, current_user, params).execute(available_commands, params[:text])
|
2016-11-17 09:30:04 -05:00
|
|
|
end
|
2016-11-16 12:28:38 -05:00
|
|
|
end
|
|
|
|
|
2016-11-17 15:27:12 -05:00
|
|
|
def match_command
|
2016-11-16 12:28:38 -05:00
|
|
|
match = nil
|
2017-01-11 09:04:49 -05:00
|
|
|
service =
|
|
|
|
available_commands.find do |klass|
|
|
|
|
match = klass.match(params[:text])
|
|
|
|
end
|
2016-11-16 12:28:38 -05:00
|
|
|
|
|
|
|
[service, match]
|
|
|
|
end
|
|
|
|
|
2016-12-16 07:32:05 -05:00
|
|
|
private
|
|
|
|
|
2016-11-17 06:06:45 -05:00
|
|
|
def available_commands
|
|
|
|
COMMANDS.select do |klass|
|
|
|
|
klass.available?(project)
|
|
|
|
end
|
2016-11-16 12:28:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|