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 03:22:09 -05:00
module Gitlab
module SlashCommands
2017-01-19 03:22:09 -05:00
module Presenters
class Help < Presenters::Base
def initialize(project, commands)
@project = project
@commands = commands
end
2017-01-30 06:12:57 -05:00
def present(trigger, text)
ephemeral_response(text: help_message(trigger, text))
2017-01-11 09:04:49 -05:00
end
2017-01-19 03:22:09 -05:00
private
2017-01-11 09:04:49 -05:00
2017-01-30 06:12:57 -05: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 06:12:57 -05:00
if text.start_with?('help')
<<~MESSAGE
#{full_commands_message(trigger)}
#{help_footer}
MESSAGE
2017-01-26 09:30:34 -05:00
else
<<~MESSAGE
The specified command is not valid.
#{full_commands_message(trigger)}
#{help_footer}
MESSAGE
2017-01-19 03:22:09 -05:00
end
end
2017-01-11 09:04:49 -05:00
def help_footer
2019-09-02 01:52:11 -04:00
message = @project ? project_info : ''
message += <<~MESSAGE
*Documentation*
2019-09-02 01:52:11 -04:00
For more information about GitLab chatops, refer to its
documentation: https://docs.gitlab.com/ce/ci/chatops/README.html.
MESSAGE
2019-09-02 01:52:11 -04: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 03:22:09 -05:00
end
end
2017-01-11 09:04:49 -05:00
end
end
end