2016-11-16 12:28:38 -05:00
|
|
|
module Gitlab
|
|
|
|
module ChatCommands
|
|
|
|
class Command < BaseCommand
|
|
|
|
COMMANDS = [
|
|
|
|
Gitlab::ChatCommands::IssueShow,
|
|
|
|
Gitlab::ChatCommands::IssueCreate,
|
2016-11-25 09:41:28 -05:00
|
|
|
Gitlab::ChatCommands::IssueSearch,
|
2016-11-21 11:26:35 -05:00
|
|
|
Gitlab::ChatCommands::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)
|
|
|
|
present command.new(project, current_user, params).execute(match)
|
|
|
|
else
|
|
|
|
access_denied
|
|
|
|
end
|
2016-11-17 09:30:04 -05:00
|
|
|
else
|
|
|
|
help(help_messages)
|
|
|
|
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
|
2016-11-17 06:06:45 -05:00
|
|
|
service = available_commands.find do |klass|
|
|
|
|
match = klass.match(command)
|
2016-11-16 12:28:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
[service, match]
|
|
|
|
end
|
|
|
|
|
2016-12-16 07:32:05 -05:00
|
|
|
private
|
|
|
|
|
2016-11-16 12:28:38 -05:00
|
|
|
def help_messages
|
2016-11-17 15:27:12 -05:00
|
|
|
available_commands.map(&:help_message)
|
2016-11-17 06:06:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def available_commands
|
|
|
|
COMMANDS.select do |klass|
|
|
|
|
klass.available?(project)
|
|
|
|
end
|
2016-11-16 12:28:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def command
|
|
|
|
params[:text]
|
|
|
|
end
|
2016-11-17 09:30:04 -05:00
|
|
|
|
|
|
|
def help(messages)
|
2016-12-15 18:00:54 -05:00
|
|
|
presenter.help(messages, params[:command])
|
2016-11-17 09:30:04 -05:00
|
|
|
end
|
2016-11-17 15:27:12 -05:00
|
|
|
|
|
|
|
def access_denied
|
2016-12-15 18:00:54 -05:00
|
|
|
presenter.access_denied
|
2016-11-17 15:27:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def present(resource)
|
2016-12-15 18:00:54 -05:00
|
|
|
presenter.present(resource)
|
2016-11-17 15:27:12 -05:00
|
|
|
end
|
2016-11-16 12:28:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|