2018-08-10 02:45:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-31 01:50:53 -04:00
|
|
|
class MattermostSlashCommandsService < SlashCommandsService
|
2016-11-14 09:10:35 -05:00
|
|
|
include TriggersHelper
|
|
|
|
|
|
|
|
prop_accessor :token
|
|
|
|
|
|
|
|
def can_test?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2016-11-13 14:35:47 -05:00
|
|
|
def title
|
2017-01-08 09:19:19 -05:00
|
|
|
'Mattermost slash commands'
|
2016-11-13 14:35:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
2017-01-08 09:19:19 -05:00
|
|
|
"Perform common operations in Mattermost"
|
2016-11-13 14:35:47 -05:00
|
|
|
end
|
|
|
|
|
2016-12-27 07:44:24 -05:00
|
|
|
def self.to_param
|
2016-11-18 10:16:45 -05:00
|
|
|
'mattermost_slash_commands'
|
2016-11-13 14:35:47 -05:00
|
|
|
end
|
|
|
|
|
2016-12-20 13:11:53 -05:00
|
|
|
def configure(user, params)
|
2017-06-21 09:48:12 -04:00
|
|
|
token = Mattermost::Command.new(user)
|
|
|
|
.create(command(params))
|
2016-12-13 13:52:41 -05:00
|
|
|
|
2016-12-20 13:11:53 -05:00
|
|
|
update(active: true, token: token) if token
|
2016-12-20 14:11:02 -05:00
|
|
|
rescue Mattermost::Error => e
|
|
|
|
[false, e.message]
|
2016-12-19 08:14:09 -05:00
|
|
|
end
|
|
|
|
|
2017-01-26 03:16:07 -05:00
|
|
|
def list_teams(current_user)
|
|
|
|
[Mattermost::Team.new(current_user).all, nil]
|
|
|
|
rescue Mattermost::Error => e
|
|
|
|
[[], e.message]
|
2016-12-13 13:52:41 -05:00
|
|
|
end
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
def chat_responder
|
|
|
|
::Gitlab::Chat::Responder::Mattermost
|
|
|
|
end
|
|
|
|
|
2016-11-17 06:06:45 -05:00
|
|
|
private
|
|
|
|
|
2016-12-19 17:53:19 -05:00
|
|
|
def command(params)
|
2018-03-05 09:15:26 -05:00
|
|
|
pretty_project_name = project.full_name
|
2016-12-16 14:29:17 -05:00
|
|
|
|
2016-12-19 17:53:19 -05:00
|
|
|
params.merge(
|
2016-12-16 14:29:17 -05:00
|
|
|
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}",
|
2016-12-21 05:53:44 -05:00
|
|
|
display_name: "GitLab / #{pretty_project_name}",
|
2016-12-16 14:29:17 -05:00
|
|
|
method: 'P',
|
2016-12-22 07:43:20 -05:00
|
|
|
username: 'GitLab')
|
2016-12-16 14:29:17 -05:00
|
|
|
end
|
2016-11-13 14:35:47 -05:00
|
|
|
end
|