diff options
author | Shinya Maeda <shinya@gitlab.com> | 2019-04-24 18:37:29 +0700 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2019-04-30 21:15:39 +0700 |
commit | daa8f784d016091fd2a56fd195cbd6da2f199350 (patch) | |
tree | 0176ed1b51776ca2224b4309ee180d269c9b0453 /app/services/ci/stop_environments_service.rb | |
parent | a96e96d5c8829348fed969d00395be93290577d4 (diff) | |
download | gitlab-ce-daa8f784d016091fd2a56fd195cbd6da2f199350.tar.gz |
Fix environment automatic on_stop trigger
Due to the nature of pipelines for merge requests, deployments.ref can
be a merge request ref instead of a branch name.
We support the environment auto-stop hook for this case
Diffstat (limited to 'app/services/ci/stop_environments_service.rb')
-rw-r--r-- | app/services/ci/stop_environments_service.rb | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/app/services/ci/stop_environments_service.rb b/app/services/ci/stop_environments_service.rb index 973ae5ce5aa..d9a800791f2 100644 --- a/app/services/ci/stop_environments_service.rb +++ b/app/services/ci/stop_environments_service.rb @@ -9,12 +9,11 @@ module Ci return unless @ref.present? - environments.each do |environment| - next unless environment.stop_action_available? - next unless can?(current_user, :stop_environment, environment) + environments.each { |environment| stop(environment) } + end - environment.stop_with_action!(current_user) - end + def execute_for_merge_request(merge_request) + merge_request.environments.each { |environment| stop(environment) } end private @@ -24,5 +23,12 @@ module Ci .new(project, current_user, ref: @ref, recently_updated: true) .execute end + + def stop(environment) + return unless environment.stop_action_available? + return unless can?(current_user, :stop_environment, environment) + + environment.stop_with_action!(current_user) + end end end |