Add help command
This commit is contained in:
parent
746f47208d
commit
53846da2c7
3 changed files with 53 additions and 8 deletions
|
@ -18,25 +18,22 @@ module Gitlab
|
||||||
Gitlab::ChatCommands::Presenters::Access.new.access_denied
|
Gitlab::ChatCommands::Presenters::Access.new.access_denied
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
help(help_messages)
|
Gitlab::ChatCommands::Help.new(project, current_user, params).execute(available_commands)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def match_command
|
def match_command
|
||||||
match = nil
|
match = nil
|
||||||
service = available_commands.find do |klass|
|
service =
|
||||||
match = klass.match(params[:text])
|
available_commands.find do |klass|
|
||||||
end
|
match = klass.match(params[:text])
|
||||||
|
end
|
||||||
|
|
||||||
[service, match]
|
[service, match]
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def help_messages
|
|
||||||
available_commands.map(&:help_message)
|
|
||||||
end
|
|
||||||
|
|
||||||
def available_commands
|
def available_commands
|
||||||
COMMANDS.select do |klass|
|
COMMANDS.select do |klass|
|
||||||
klass.available?(project)
|
klass.available?(project)
|
||||||
|
|
28
lib/gitlab/chat_commands/help.rb
Normal file
28
lib/gitlab/chat_commands/help.rb
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
module Gitlab
|
||||||
|
module ChatCommands
|
||||||
|
class Help < BaseCommand
|
||||||
|
# This class has to be used last, as it always matches. It has to match
|
||||||
|
# because other commands were not triggered and we want to show the help
|
||||||
|
# command
|
||||||
|
def self.match(_text)
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.help_message
|
||||||
|
'help'
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.allowed?(_project, _user)
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def execute(commands)
|
||||||
|
Gitlab::ChatCommands::Presenters::Help.new(commands).present(trigger)
|
||||||
|
end
|
||||||
|
|
||||||
|
def trigger
|
||||||
|
params[:command]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
20
lib/gitlab/chat_commands/presenters/help.rb
Normal file
20
lib/gitlab/chat_commands/presenters/help.rb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
module Gitlab::ChatCommands::Presenters
|
||||||
|
class Help < Gitlab::ChatCommands::Presenters::Base
|
||||||
|
def present(trigger)
|
||||||
|
message =
|
||||||
|
if @resource.none?
|
||||||
|
"No commands available :thinking_face:"
|
||||||
|
else
|
||||||
|
header_with_list("Available commands", full_commands(trigger))
|
||||||
|
end
|
||||||
|
|
||||||
|
ephemeral_response(text: message)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def full_commands(trigger)
|
||||||
|
@resource.map { |command| "#{trigger} #{command.help_message}" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue