summaryrefslogtreecommitdiff
path: root/app/services
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
parente671cd89956874e05812032400ba2910581f7de1 (diff)
downloadgitlab-ce-04a8372cdfff501fe67c17612a0b5e098f7d56c9.tar.gz
Add environment teardown service
Diffstat (limited to 'app/services')
-rw-r--r--app/services/ci/stop_environment_service.rb31
-rw-r--r--app/services/delete_branch_service.rb2
2 files changed, 33 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
diff --git a/app/services/delete_branch_service.rb b/app/services/delete_branch_service.rb
index 3e5dd4ebb86..ec8ee7452d6 100644
--- a/app/services/delete_branch_service.rb
+++ b/app/services/delete_branch_service.rb
@@ -21,6 +21,8 @@ class DeleteBranchService < BaseService
return error('You dont have push access to repo', 405)
end
+ # StopEnvironmentService
+
if repository.rm_branch(current_user, branch_name)
success('Branch was removed')
else