2018-11-20 02:01:13 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-19 08:22:09 +00:00
|
|
|
module Gitlab
|
2017-05-31 05:50:53 +00:00
|
|
|
module SlashCommands
|
2017-01-19 08:22:09 +00:00
|
|
|
module Presenters
|
|
|
|
class Help < Presenters::Base
|
2019-08-26 12:23:36 +00:00
|
|
|
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)
|
2019-08-26 12:23:36 +00:00
|
|
|
unless @commands.present?
|
|
|
|
return <<~MESSAGE
|
|
|
|
This chatops integration does not have any commands that can be
|
|
|
|
executed.
|
|
|
|
|
2020-06-16 09:08:27 +00:00
|
|
|
#{help_footer}
|
2019-08-26 12:23:36 +00:00
|
|
|
MESSAGE
|
|
|
|
end
|
2017-01-30 11:12:57 +00:00
|
|
|
|
|
|
|
if text.start_with?('help')
|
2019-08-26 12:23:36 +00:00
|
|
|
<<~MESSAGE
|
|
|
|
#{full_commands_message(trigger)}
|
|
|
|
|
|
|
|
#{help_footer}
|
|
|
|
MESSAGE
|
2017-01-26 14:30:34 +00:00
|
|
|
else
|
2019-08-26 12:23:36 +00:00
|
|
|
<<~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
|
|
|
|
2019-08-26 12:23:36 +00:00
|
|
|
def help_footer
|
2019-09-02 05:52:11 +00:00
|
|
|
message = @project ? project_info : ''
|
|
|
|
message += <<~MESSAGE
|
|
|
|
*Documentation*
|
2019-09-02 05:35:45 +00:00
|
|
|
|
2019-09-02 05:52:11 +00:00
|
|
|
For more information about GitLab chatops, refer to its
|
2020-10-14 12:08:58 +00:00
|
|
|
documentation: https://docs.gitlab.com/ee/ci/chatops/README.html.
|
2019-09-02 05:35:45 +00:00
|
|
|
MESSAGE
|
2019-09-02 05:52:11 +00:00
|
|
|
|
|
|
|
message
|
2019-09-02 05:35:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def project_info
|
2019-08-26 12:23:36 +00:00
|
|
|
<<~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
|