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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.3 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
module Gitlab
module SlashCommands
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::IssueClose,
Gitlab::SlashCommands::IssueComment,
Gitlab::SlashCommands::Deploy,
Gitlab::SlashCommands::Run
2018-06-04 12:42:02 +00:00
]
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(project)
end
2016-11-17 14:30:04 +00:00
else
Gitlab::SlashCommands::Help.new(project, chat_name, 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
2018-06-04 12:42:02 +00:00
self.class.commands.keep_if do |klass|
klass.available?(project)
end
end
end
end
end