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

45 lines
1.0 KiB
Ruby
Raw Normal View History

module Gitlab
module ChatCommands
class Command < BaseCommand
COMMANDS = [
Gitlab::ChatCommands::IssueShow,
2017-01-26 14:30:34 +00:00
Gitlab::ChatCommands::IssueNew,
Gitlab::ChatCommands::IssueSearch,
Gitlab::ChatCommands::Deploy
].freeze
def execute
command, match = match_command
if command
if command.allowed?(project, current_user)
command.new(project, current_user, params).execute(match)
else
Gitlab::ChatCommands::Presenters::Access.new.access_denied
end
2016-11-17 14:30:04 +00:00
else
2017-01-30 11:12:57 +00:00
Gitlab::ChatCommands::Help.new(project, current_user, params).execute(available_commands, params[:text])
2016-11-17 14:30:04 +00:00
end
end
def match_command
match = nil
2017-01-11 14:04:49 +00:00
service =
available_commands.find do |klass|
match = klass.match(params[:text])
end
[service, match]
end
2016-12-16 12:32:05 +00:00
private
def available_commands
COMMANDS.select do |klass|
klass.available?(project)
end
end
end
end
end