Class: Gitlab::SlashCommands::Deploy

Inherits:
BaseCommand show all
Defined in:
lib/gitlab/slash_commands/deploy.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

can?, #collection, #initialize

Constructor Details

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

Class Method Details

.allowed?(project, user) ⇒ Boolean

Returns:

  • (Boolean)

18
19
20
# File 'lib/gitlab/slash_commands/deploy.rb', line 18

def self.allowed?(project, user)
  can?(user, :create_deployment, project)
end

.available?(project) ⇒ Boolean

Returns:

  • (Boolean)

14
15
16
# File 'lib/gitlab/slash_commands/deploy.rb', line 14

def self.available?(project)
  project.builds_enabled?
end

.help_messageObject


10
11
12
# File 'lib/gitlab/slash_commands/deploy.rb', line 10

def self.help_message
  'deploy <environment> to <target-environment>'
end

.match(text) ⇒ Object


6
7
8
# File 'lib/gitlab/slash_commands/deploy.rb', line 6

def self.match(text)
  /\Adeploy\s+(?<from>\S+.*)\s+to+\s+(?<to>\S+.*)\z/.match(text)
end

Instance Method Details

#execute(match) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gitlab/slash_commands/deploy.rb', line 22

def execute(match)
  from = match[:from]
  to = match[:to]

  action = find_action(from, to)

  if action.nil?
    Gitlab::SlashCommands::Presenters::Deploy
      .new(action).action_not_found
  else
    deployment = action.play(current_user)

    Gitlab::SlashCommands::Presenters::Deploy
      .new(deployment).present(from, to)
  end
end