debian-mirror-gitlab/lib/gitlab/slash_commands/command.rb

47 lines
1.1 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
module Gitlab
2017-09-10 17:25:29 +05:30
module SlashCommands
2017-08-17 22:00:37 +05:30
class Command < BaseCommand
COMMANDS = [
2017-09-10 17:25:29 +05:30
Gitlab::SlashCommands::IssueShow,
Gitlab::SlashCommands::IssueNew,
Gitlab::SlashCommands::IssueSearch,
2018-05-09 12:01:36 +05:30
Gitlab::SlashCommands::IssueMove,
2017-09-10 17:25:29 +05:30
Gitlab::SlashCommands::Deploy
2017-08-17 22:00:37 +05:30
].freeze
def execute
command, match = match_command
if command
if command.allowed?(project, current_user)
2018-03-27 19:54:05 +05:30
command.new(project, chat_name, params).execute(match)
2017-08-17 22:00:37 +05:30
else
2017-09-10 17:25:29 +05:30
Gitlab::SlashCommands::Presenters::Access.new.access_denied
2017-08-17 22:00:37 +05:30
end
else
2018-03-27 19:54:05 +05:30
Gitlab::SlashCommands::Help.new(project, chat_name, params)
.execute(available_commands, params[:text])
2017-08-17 22:00:37 +05:30
end
end
def match_command
match = nil
service =
available_commands.find do |klass|
match = klass.match(params[:text])
end
[service, match]
end
private
def available_commands
COMMANDS.select do |klass|
klass.available?(project)
end
end
end
end
end