debian-mirror-gitlab/lib/gitlab/slash_commands/presenters/help.rb

97 lines
2.4 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Gitlab
2017-09-10 17:25:29 +05:30
module SlashCommands
2017-08-17 22:00:37 +05:30
module Presenters
class Help < Presenters::Base
2023-01-13 00:05:48 +05:30
def initialize(project, commands, params = {})
2019-12-04 20:38:33 +05:30
@project = project
@commands = commands
2023-01-13 00:05:48 +05:30
@params = params
2019-12-04 20:38:33 +05:30
end
2017-08-17 22:00:37 +05:30
def present(trigger, text)
ephemeral_response(text: help_message(trigger, text))
end
private
def help_message(trigger, text)
2019-12-04 20:38:33 +05:30
unless @commands.present?
return <<~MESSAGE
This chatops integration does not have any commands that can be
executed.
2020-06-23 00:09:42 +05:30
#{help_footer}
2019-12-04 20:38:33 +05:30
MESSAGE
end
2017-08-17 22:00:37 +05:30
2023-04-23 21:23:45 +05:30
if text && text.start_with?('help')
2019-12-04 20:38:33 +05:30
<<~MESSAGE
#{full_commands_message(trigger)}
#{help_footer}
MESSAGE
2017-08-17 22:00:37 +05:30
else
2019-12-04 20:38:33 +05:30
<<~MESSAGE
The specified command is not valid.
#{full_commands_message(trigger)}
#{help_footer}
MESSAGE
2017-08-17 22:00:37 +05:30
end
end
2019-12-04 20:38:33 +05:30
def help_footer
message = @project ? project_info : ''
message += <<~MESSAGE
*Documentation*
For more information about GitLab chatops, refer to its
2021-10-27 15:23:28 +05:30
documentation: https://docs.gitlab.com/ee/ci/chatops/index.html.
2019-12-04 20:38:33 +05:30
MESSAGE
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
2023-01-13 00:05:48 +05:30
.map do |command|
if command < Gitlab::SlashCommands::IncidentManagement::IncidentCommand
"#{trigger} #{command.help_message}"
2023-04-23 21:23:45 +05:30
else
"#{trigger} [project name or alias] #{command.help_message}"
2023-01-13 00:05:48 +05:30
end
end
2019-12-04 20:38:33 +05:30
.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-08-17 22:00:37 +05:30
end
end
end
end
end