2016-11-16 17:28:38 +00:00
|
|
|
module Gitlab
|
2017-05-31 05:50:53 +00:00
|
|
|
module SlashCommands
|
2016-11-16 17:28:38 +00:00
|
|
|
class Command < BaseCommand
|
2018-06-04 12:42:02 +00:00
|
|
|
def self.commands
|
|
|
|
[
|
|
|
|
Gitlab::SlashCommands::IssueShow,
|
|
|
|
Gitlab::SlashCommands::IssueNew,
|
|
|
|
Gitlab::SlashCommands::IssueSearch,
|
|
|
|
Gitlab::SlashCommands::IssueMove,
|
|
|
|
Gitlab::SlashCommands::Deploy
|
|
|
|
]
|
|
|
|
end
|
2016-11-16 17:28:38 +00:00
|
|
|
|
|
|
|
def execute
|
2016-11-17 20:27:12 +00:00
|
|
|
command, match = match_command
|
|
|
|
|
|
|
|
if command
|
|
|
|
if command.allowed?(project, current_user)
|
2018-02-22 17:34:04 +00:00
|
|
|
command.new(project, chat_name, params).execute(match)
|
2016-11-17 20:27:12 +00:00
|
|
|
else
|
2017-05-31 05:50:53 +00:00
|
|
|
Gitlab::SlashCommands::Presenters::Access.new.access_denied
|
2016-11-17 20:27:12 +00:00
|
|
|
end
|
2016-11-17 14:30:04 +00:00
|
|
|
else
|
2018-02-22 17:34:04 +00:00
|
|
|
Gitlab::SlashCommands::Help.new(project, chat_name, 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
|
2018-06-04 12:42:02 +00:00
|
|
|
self.class.commands.keep_if do |klass|
|
2016-11-17 11:06:45 +00:00
|
|
|
klass.available?(project)
|
|
|
|
end
|
2016-11-16 17:28:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|