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

90 lines
2.1 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
2019-12-04 20:38:33 +05:30
def initialize(project, commands)
@project = project
@commands = commands
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
if 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
documentation: https://docs.gitlab.com/ce/ci/chatops/README.html.
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
.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-08-17 22:00:37 +05:30
end
end
end
end
end