gitlab-org--gitlab-foss/lib/gitlab/slash_commands/presenters/help.rb

90 lines
2.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2017-01-19 08:22:09 +00:00
module Gitlab
module SlashCommands
2017-01-19 08:22:09 +00:00
module Presenters
class Help < Presenters::Base
def initialize(project, commands)
@project = project
@commands = commands
end
2017-01-30 11:12:57 +00:00
def present(trigger, text)
ephemeral_response(text: help_message(trigger, text))
2017-01-11 14:04:49 +00:00
end
2017-01-19 08:22:09 +00:00
private
2017-01-11 14:04:49 +00:00
2017-01-30 11:12:57 +00:00
def help_message(trigger, text)
unless @commands.present?
return <<~MESSAGE
This chatops integration does not have any commands that can be
executed.
#{help_footer}
MESSAGE
end
2017-01-30 11:12:57 +00:00
if text.start_with?('help')
<<~MESSAGE
#{full_commands_message(trigger)}
#{help_footer}
MESSAGE
2017-01-26 14:30:34 +00:00
else
<<~MESSAGE
The specified command is not valid.
#{full_commands_message(trigger)}
#{help_footer}
MESSAGE
2017-01-19 08:22:09 +00:00
end
end
2017-01-11 14:04:49 +00:00
def help_footer
2019-09-02 05:52:11 +00:00
message = @project ? project_info : ''
message += <<~MESSAGE
*Documentation*
2019-09-02 05:52:11 +00:00
For more information about GitLab chatops, refer to its
documentation: https://docs.gitlab.com/ee/ci/chatops/README.html.
MESSAGE
2019-09-02 05:52:11 +00:00
message
end
def project_info
<<~MESSAGE
*Project*
The GitLab project for this chatops integration can be found at
#{url_for(@project)}.
MESSAGE
end
def full_commands_message(trigger)
list = @commands
.map { |command| "#{trigger} #{command.help_message}" }
.join("\n")
<<~MESSAGE
*Available commands*
The following commands are available for this chatops integration:
#{list}
If available, the `run` command is used for running GitLab CI jobs
defined in this project's `.gitlab-ci.yml` file. For example, if a
job called "help" is defined you can run it like so:
`#{trigger} run help`
MESSAGE
2017-01-19 08:22:09 +00:00
end
end
2017-01-11 14:04:49 +00:00
end
end
end