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

52 lines
1.2 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
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
2018-11-08 19:23:39 +05:30
def self.commands
[
Gitlab::SlashCommands::IssueShow,
Gitlab::SlashCommands::IssueNew,
Gitlab::SlashCommands::IssueSearch,
Gitlab::SlashCommands::IssueMove,
2019-05-18 00:54:41 +05:30
Gitlab::SlashCommands::Deploy,
Gitlab::SlashCommands::Run
2018-11-08 19:23:39 +05:30
]
end
2017-08-17 22:00:37 +05:30
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
2018-11-08 19:23:39 +05:30
self.class.commands.keep_if do |klass|
2017-08-17 22:00:37 +05:30
klass.available?(project)
end
end
end
end
end