debian-mirror-gitlab/app/models/project_services/mattermost_slash_commands_service.rb

58 lines
1.2 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
class MattermostSlashCommandsService < SlashCommandsService
2021-03-08 18:12:59 +05:30
include Ci::TriggersHelper
2017-08-17 22:00:37 +05:30
prop_accessor :token
def can_test?
false
end
def title
'Mattermost slash commands'
end
def description
2021-04-29 21:17:54 +05:30
"Perform common tasks with slash commands."
2017-08-17 22:00:37 +05:30
end
def self.to_param
'mattermost_slash_commands'
end
def configure(user, params)
2017-09-10 17:25:29 +05:30
token = Mattermost::Command.new(user)
.create(command(params))
2017-08-17 22:00:37 +05:30
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
2020-05-24 23:13:21 +05:30
def chat_responder
::Gitlab::Chat::Responder::Mattermost
end
2017-08-17 22:00:37 +05:30
private
def command(params)
2018-03-27 19:54:05 +05:30
pretty_project_name = project.full_name
2017-08-17 22:00:37 +05:30
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