summaryrefslogtreecommitdiff
path: root/app/services/ci
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-11-08 14:20:58 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-11-08 14:20:58 +0100
commit04a8372cdfff501fe67c17612a0b5e098f7d56c9 (patch)
tree27c3236d137ed4434cff5450d24093cbc3c563e8 /app/services/ci
parente671cd89956874e05812032400ba2910581f7de1 (diff)
downloadgitlab-ce-04a8372cdfff501fe67c17612a0b5e098f7d56c9.tar.gz
Add environment teardown service
Diffstat (limited to 'app/services/ci')
-rw-r--r--app/services/ci/stop_environment_service.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/app/services/ci/stop_environment_service.rb b/app/services/ci/stop_environment_service.rb
new file mode 100644
index 00000000000..5c208b738f7
--- /dev/null
+++ b/app/services/ci/stop_environment_service.rb
@@ -0,0 +1,31 @@
+module Ci
+ class StopEnvironmentService < BaseService
+ def execute(ref)
+ @ref = ref
+ @commit = project.commit(ref)
+
+ return unless has_ref_sha_pair?
+ return unless has_environments?
+
+ environments.each do |environment|
+ next unless environment.stoppable?
+
+ environment.stop!(current_user)
+ end
+ end
+
+ private
+
+ def has_ref_sha_pair?
+ @ref && @commit
+ end
+
+ def has_environments?
+ environments.any?
+ end
+
+ def environments
+ @environments ||= project.environments_for(@ref, @commit)
+ end
+ end
+end