diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-11-21 17:26:35 +0100 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-11-21 17:26:35 +0100 |
commit | a36d556137116385e84eca592ec62e46ecb97e03 (patch) | |
tree | 439638d981ab25807843c19ed2b369344d27f67c /lib | |
parent | 1d16f137d93576385e403f5caf5f64bfe0b3a647 (diff) | |
download | gitlab-ce-a36d556137116385e84eca592ec62e46ecb97e03.tar.gz |
Introduce deploy command that allows to start deployment from one environment to second onechatops-deploy-command
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/chat_commands/command.rb | 1 | ||||
-rw-r--r-- | lib/gitlab/chat_commands/deploy.rb | 20 |
2 files changed, 16 insertions, 5 deletions
diff --git a/lib/gitlab/chat_commands/command.rb b/lib/gitlab/chat_commands/command.rb index 5f131703d40..0ec358debc7 100644 --- a/lib/gitlab/chat_commands/command.rb +++ b/lib/gitlab/chat_commands/command.rb @@ -4,6 +4,7 @@ module Gitlab COMMANDS = [ Gitlab::ChatCommands::IssueShow, Gitlab::ChatCommands::IssueCreate, + Gitlab::ChatCommands::Deploy, ].freeze def execute diff --git a/lib/gitlab/chat_commands/deploy.rb b/lib/gitlab/chat_commands/deploy.rb index 8165d52575d..c0b93cca68c 100644 --- a/lib/gitlab/chat_commands/deploy.rb +++ b/lib/gitlab/chat_commands/deploy.rb @@ -9,6 +9,10 @@ module Gitlab 'deploy <environment> to <target-environment>' end + def self.available?(project) + project.builds_enabled? + end + def self.allowed?(project, user) can?(user, :create_deployment, project) end @@ -17,11 +21,8 @@ module Gitlab from = match[:from] to = match[:to] - environment = project.environments.find_by(name: from) - return unless environment - - actions = environment.actions_for(to) - return unless actions.any? + actions = find_actions(from, to) + return unless actions.present? if actions.one? actions.first.play(current_user) @@ -29,6 +30,15 @@ module Gitlab Result.new(:error, 'Too many actions defined') end end + + private + + def find_actions(from, to) + environment = project.environments.find_by(name: from) + return unless environment + + environment.actions_for(to).select(&:starts_environment?) + end end end end |