2016-12-16 08:21:06 -05:00
|
|
|
class MattermostSlashCommandsService < ChatSlashCommandsService
|
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
|
2016-11-17 06:06:45 -05:00
|
|
|
'Mattermost Command'
|
2016-11-13 14:35:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
2016-11-18 07:29:47 -05:00
|
|
|
"Perform common operations on GitLab 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)
|
2016-12-19 18:22:10 -05: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
|
|
|
|
|
2016-11-17 06:06:45 -05:00
|
|
|
private
|
|
|
|
|
2016-12-19 17:53:19 -05:00
|
|
|
def command(params)
|
2016-12-16 14:29:17 -05:00
|
|
|
pretty_project_name = project.name_with_namespace
|
|
|
|
|
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
|