gitlab-org--gitlab-foss/lib/gitlab/slash_commands/command.rb
James Fargher 2d19b1adef Move ChatOps to Core
ChatOps used to be in the Ultimate tier.
2019-02-20 21:29:48 +00:00

51 lines
1.2 KiB
Ruby

# frozen_string_literal: true
module Gitlab
module SlashCommands
class Command < BaseCommand
def self.commands
[
Gitlab::SlashCommands::IssueShow,
Gitlab::SlashCommands::IssueNew,
Gitlab::SlashCommands::IssueSearch,
Gitlab::SlashCommands::IssueMove,
Gitlab::SlashCommands::Deploy,
Gitlab::SlashCommands::Run
]
end
def execute
command, match = match_command
if command
if command.allowed?(project, current_user)
command.new(project, chat_name, params).execute(match)
else
Gitlab::SlashCommands::Presenters::Access.new.access_denied
end
else
Gitlab::SlashCommands::Help.new(project, chat_name, params)
.execute(available_commands, params[:text])
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
self.class.commands.keep_if do |klass|
klass.available?(project)
end
end
end
end
end