2016-12-16 13:21:06 +00:00
|
|
|
class MattermostSlashCommandsService < ChatSlashCommandsService
|
2016-11-14 14:10:35 +00:00
|
|
|
include TriggersHelper
|
|
|
|
|
|
|
|
prop_accessor :token
|
|
|
|
|
|
|
|
def can_test?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2016-11-13 19:35:47 +00:00
|
|
|
def title
|
2016-11-17 11:06:45 +00:00
|
|
|
'Mattermost Command'
|
2016-11-13 19:35:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
2016-11-18 12:29:47 +00:00
|
|
|
"Perform common operations on GitLab in Mattermost"
|
2016-11-13 19:35:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_param
|
2016-11-18 15:16:45 +00:00
|
|
|
'mattermost_slash_commands'
|
2016-11-13 19:35:47 +00:00
|
|
|
end
|
|
|
|
|
2016-12-20 18:11:53 +00:00
|
|
|
def configure(user, params)
|
2016-12-19 23:22:10 +00:00
|
|
|
token = Mattermost::Command.new(user).
|
|
|
|
create(command(params))
|
2016-12-13 18:52:41 +00:00
|
|
|
|
2016-12-20 18:11:53 +00:00
|
|
|
update(active: true, token: token) if token
|
2016-12-20 19:11:02 +00:00
|
|
|
rescue Mattermost::Error => e
|
|
|
|
[false, e.message]
|
2016-12-19 13:14:09 +00:00
|
|
|
end
|
|
|
|
|
2016-12-19 22:53:19 +00:00
|
|
|
def list_teams(user)
|
2016-12-19 23:22:10 +00:00
|
|
|
Mattermost::Team.new(user).all
|
2016-12-21 10:53:44 +00:00
|
|
|
rescue Mattermost::Error => e
|
|
|
|
[[], e.message]
|
2016-12-13 18:52:41 +00:00
|
|
|
end
|
|
|
|
|
2016-11-17 11:06:45 +00:00
|
|
|
private
|
|
|
|
|
2016-12-19 22:53:19 +00:00
|
|
|
def command(params)
|
2016-12-16 19:29:17 +00:00
|
|
|
pretty_project_name = project.name_with_namespace
|
|
|
|
|
2016-12-19 22:53:19 +00:00
|
|
|
params.merge(
|
2016-12-16 19:29:17 +00: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 10:53:44 +00:00
|
|
|
display_name: "GitLab / #{pretty_project_name}",
|
2016-12-16 19:29:17 +00:00
|
|
|
method: 'P',
|
2016-12-19 22:53:19 +00:00
|
|
|
user_name: 'GitLab')
|
2016-12-16 19:29:17 +00:00
|
|
|
end
|
2016-11-13 19:35:47 +00:00
|
|
|
end
|