gitlab-org--gitlab-foss/lib/gitlab/chat_commands/command.rb

64 lines
1.3 KiB
Ruby
Raw Normal View History

module Gitlab
module ChatCommands
class Command < BaseCommand
COMMANDS = [
Gitlab::ChatCommands::IssueShow,
Gitlab::ChatCommands::IssueCreate,
Gitlab::ChatCommands::IssueSearch,
Gitlab::ChatCommands::Deploy,
].freeze
def execute
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
end
def match_command
match = nil
service = available_commands.find do |klass|
match = klass.match(command)
end
[service, match]
end
2016-12-16 07:32:05 -05:00
private
def help_messages
available_commands.map(&:help_message)
end
def available_commands
COMMANDS.select do |klass|
klass.available?(project)
end
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
def access_denied
2016-12-15 18:00:54 -05:00
presenter.access_denied
end
def present(resource)
2016-12-15 18:00:54 -05:00
presenter.present(resource)
end
end
end
end