Commit 53846da2 authored by Z.J. van de Weg's avatar Z.J. van de Weg

Add help command

parent 746f4720
...@@ -18,25 +18,22 @@ module Gitlab ...@@ -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)
......
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
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment