Class: Gitlab::SlashCommands::Command

Inherits:
BaseCommand show all
Defined in:
lib/gitlab/slash_commands/command.rb

Constant Summary

Constants inherited from BaseCommand

BaseCommand::QUERY_LIMIT

Instance Attribute Summary

Attributes inherited from BaseCommand

#chat_name, #current_user, #params, #project

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCommand

allowed?, available?, can?, #collection, help_message, #initialize, match

Constructor Details

This class inherits a constructor from Gitlab::SlashCommands::BaseCommand

Class Method Details

.commandsObject


6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/gitlab/slash_commands/command.rb', line 6

def self.commands
  [
    Gitlab::SlashCommands::IssueShow,
    Gitlab::SlashCommands::IssueNew,
    Gitlab::SlashCommands::IssueSearch,
    Gitlab::SlashCommands::IssueMove,
    Gitlab::SlashCommands::IssueClose,
    Gitlab::SlashCommands::IssueComment,
    Gitlab::SlashCommands::Deploy,
    Gitlab::SlashCommands::Run
  ]
end

Instance Method Details

#executeObject


19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gitlab/slash_commands/command.rb', line 19

def execute
  command, match = match_command

  if command
    if command.allowed?(project, current_user)
      command.new(project, chat_name, params).execute(match)
    else
      Gitlab::SlashCommands::Presenters::Access.new.access_denied(project)
    end
  else
    Gitlab::SlashCommands::Help.new(project, chat_name, params)
      .execute(available_commands, params[:text])
  end
end

#match_commandObject


34
35
36
37
38
39
40
41
42
# File 'lib/gitlab/slash_commands/command.rb', line 34

def match_command
  match = nil
  service =
    available_commands.find do |klass|
      match = klass.match(params[:text])
    end

  [service, match]
end