diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-07-28 10:56:50 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-07-28 10:56:50 +0200 |
commit | 29a8827752b884f5e4cad4ec78cf5b655aa5c769 (patch) | |
tree | 0562868430c678b7a04fa5e733ec6657e8575381 /lib/gitlab/slash_commands/deploy.rb | |
parent | 3f1b7b88c8d4f19a10920ad1629fc440af584d08 (diff) | |
download | gitlab-ce-29a8827752b884f5e4cad4ec78cf5b655aa5c769.tar.gz |
Improve deploy environment chatops slash command
We now match deployment actions better. If there is more than one
deployment action matched, we check if there is an action which name
equals to environment name, instead of raising an error about too many
actions defined.
Diffstat (limited to 'lib/gitlab/slash_commands/deploy.rb')
-rw-r--r-- | lib/gitlab/slash_commands/deploy.rb | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/lib/gitlab/slash_commands/deploy.rb b/lib/gitlab/slash_commands/deploy.rb index e71eb15d604..93e00ab75a1 100644 --- a/lib/gitlab/slash_commands/deploy.rb +++ b/lib/gitlab/slash_commands/deploy.rb @@ -21,29 +21,34 @@ module Gitlab from = match[:from] to = match[:to] - actions = find_actions(from, to) + action = find_action(from, to) - if actions.none? - Gitlab::SlashCommands::Presenters::Deploy.new(nil).no_actions - elsif actions.one? - action = play!(from, to, actions.first) - Gitlab::SlashCommands::Presenters::Deploy.new(action).present(from, to) + if action.nil? + Gitlab::SlashCommands::Presenters::Deploy + .new(action).action_not_found else - Gitlab::SlashCommands::Presenters::Deploy.new(actions).too_many_actions + deployment = action.play(current_user) + + Gitlab::SlashCommands::Presenters::Deploy + .new(deployment).present(from, to) end end private - def play!(from, to, action) - action.play(current_user) - end - - def find_actions(from, to) + def find_action(from, to) environment = project.environments.find_by(name: from) - return [] unless environment + return unless environment - environment.actions_for(to).select(&:starts_environment?) + actions = environment.actions_for(to).select do |action| + action.starts_environment? + end + + if actions.many? + actions.find { |action| action.name == to.to_s } + else + actions.first + end end end end |