summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
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