2016-11-16 17:28:38 +00:00
|
|
|
module Gitlab
|
|
|
|
module ChatCommands
|
|
|
|
class Command < BaseCommand
|
|
|
|
COMMANDS = [
|
|
|
|
Gitlab::ChatCommands::IssueShow,
|
2017-01-26 14:30:34 +00:00
|
|
|
Gitlab::ChatCommands::IssueNew,
|
2016-11-25 14:41:28 +00:00
|
|
|
Gitlab::ChatCommands::IssueSearch,
|
2017-05-03 11:22:03 +00:00
|
|
|
Gitlab::ChatCommands::Deploy
|
2016-11-16 17:28:38 +00:00
|
|
|
].freeze
|
|
|
|
|
|
|
|
def execute
|
2016-11-17 20:27:12 +00:00
|
|
|
command, match = match_command
|
|
|
|
|
|
|
|
if command
|
|
|
|
if command.allowed?(project, current_user)
|
2017-01-10 18:43:58 +00:00
|
|
|
command.new(project, current_user, params).execute(match)
|
2016-11-17 20:27:12 +00:00
|
|
|
else
|
2017-01-10 18:43:58 +00:00
|
|
|
Gitlab::ChatCommands::Presenters::Access.new.access_denied
|
2016-11-17 20:27:12 +00:00
|
|
|
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
|
2016-11-16 17:28:38 +00:00
|
|
|
end
|
|
|
|
|
2016-11-17 20:27:12 +00:00
|
|
|
def match_command
|
2016-11-16 17:28:38 +00:00
|
|
|
match = nil
|
2017-01-11 14:04:49 +00:00
|
|
|
service =
|
|
|
|
available_commands.find do |klass|
|
|
|
|
match = klass.match(params[:text])
|
|
|
|
end
|
2016-11-16 17:28:38 +00:00
|
|
|
|
|
|
|
[service, match]
|
|
|
|
end
|
|
|
|
|
2016-12-16 12:32:05 +00:00
|
|
|
private
|
|
|
|
|
2016-11-17 11:06:45 +00:00
|
|
|
def available_commands
|
|
|
|
COMMANDS.select do |klass|
|
|
|
|
klass.available?(project)
|
|
|
|
end
|
2016-11-16 17:28:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|