mattermost_slash_commands_service.rb 1.09 KB
Newer Older
1
class MattermostSlashCommandsService < ChatSlashCommandsService
2 3 4 5 6 7 8 9
  include TriggersHelper

  prop_accessor :token

  def can_test?
    false
  end

10
  def title
11
    'Mattermost slash commands'
12 13 14
  end

  def description
15
    "Perform common operations in Mattermost"
16 17
  end

18
  def self.to_param
19
    'mattermost_slash_commands'
20 21
  end

Kamil Trzcinski's avatar
WIP  
Kamil Trzcinski committed
22
  def configure(user, params)
Kamil Trzcinski's avatar
Kamil Trzcinski committed
23 24
    token = Mattermost::Command.new(user).
      create(command(params))
25

Kamil Trzcinski's avatar
WIP  
Kamil Trzcinski committed
26
    update(active: true, token: token) if token
27 28
  rescue Mattermost::Error => e
    [false, e.message]
29 30
  end

31 32 33 34
  def list_teams(current_user)
    [Mattermost::Team.new(current_user).all, nil]
  rescue Mattermost::Error => e
    [[], e.message]
35 36
  end

37 38
  private

Kamil Trzcinski's avatar
Kamil Trzcinski committed
39
  def command(params)
Z.J. van de Weg's avatar
Z.J. van de Weg committed
40 41
    pretty_project_name = project.name_with_namespace

Kamil Trzcinski's avatar
Kamil Trzcinski committed
42
    params.merge(
Z.J. van de Weg's avatar
Z.J. van de Weg committed
43 44 45 46
      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}",
Kamil Trzcinski's avatar
Kamil Trzcinski committed
47
      display_name: "GitLab / #{pretty_project_name}",
Z.J. van de Weg's avatar
Z.J. van de Weg committed
48
      method: 'P',
49
      username: 'GitLab')
Z.J. van de Weg's avatar
Z.J. van de Weg committed
50
  end
51
end