gitlab-org--gitlab-foss/app/models/project_services/mattermost_slash_commands_service.rb

52 lines
1.1 KiB
Ruby
Raw Normal View History

2016-12-16 08:21:06 -05:00
class MattermostSlashCommandsService < ChatSlashCommandsService
include TriggersHelper
prop_accessor :token
def can_test?
false
end
def title
'Mattermost Command'
end
def description
2016-11-18 07:29:47 -05:00
"Perform common operations on GitLab in Mattermost"
end
def self.to_param
'mattermost_slash_commands'
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-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]
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]
end
private
def command(params)
2016-12-16 14:29:17 -05:00
pretty_project_name = project.name_with_namespace
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',
username: 'GitLab')
2016-12-16 14:29:17 -05:00
end
end