debian-mirror-gitlab/app/models/integrations/mattermost_slash_commands.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.5 KiB
Ruby
Raw Normal View History

2021-09-04 01:27:46 +05:30
# frozen_string_literal: true
module Integrations
class MattermostSlashCommands < BaseSlashCommands
include Ci::TriggersHelper
2023-05-27 22:25:52 +05:30
field :token,
type: 'password',
non_empty_password_title: -> { s_('ProjectService|Enter new token') },
non_empty_password_help: -> { s_('ProjectService|Leave blank to use your current token.') },
placeholder: ''
2021-09-04 01:27:46 +05:30
2021-09-30 23:02:18 +05:30
def testable?
2021-09-04 01:27:46 +05:30
false
end
def title
2023-06-20 00:43:36 +05:30
s_('Integrations|Mattermost slash commands')
2021-09-04 01:27:46 +05:30
end
def description
2023-06-20 00:43:36 +05:30
s_('Integrations|Perform common tasks with slash commands.')
2021-09-04 01:27:46 +05:30
end
def self.to_param
'mattermost_slash_commands'
end
def configure(user, params)
token = ::Mattermost::Command.new(user)
.create(command(params))
update(active: true, token: token) if token
rescue ::Mattermost::Error => e
[false, e.message]
end
def list_teams(current_user)
[::Mattermost::Team.new(current_user).all, nil]
rescue ::Mattermost::Error => e
[[], e.message]
end
private
def command(params)
pretty_project_name = project.full_name
params.merge(
auto_complete: true,
auto_complete_desc: "Perform common operations on: #{pretty_project_name}",
auto_complete_hint: '[help]',
description: "Perform common operations on: #{pretty_project_name}",
display_name: "GitLab / #{pretty_project_name}",
method: 'P',
username: 'GitLab')
end
end
end