debian-mirror-gitlab/app/services/environments/stop_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
849 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2021-10-27 15:23:28 +05:30
module Environments
class StopService < BaseService
2017-08-17 22:00:37 +05:30
attr_reader :ref
2021-10-27 15:23:28 +05:30
def execute(environment)
return unless can?(current_user, :stop_environment, environment)
2022-06-21 17:19:12 +05:30
environment.stop_with_actions!(current_user)
2021-10-27 15:23:28 +05:30
end
def execute_for_branch(branch_name)
2017-08-17 22:00:37 +05:30
@ref = branch_name
return unless @ref.present?
2021-10-27 15:23:28 +05:30
environments.each { |environment| execute(environment) }
2019-07-07 11:18:12 +05:30
end
2017-08-17 22:00:37 +05:30
2019-07-07 11:18:12 +05:30
def execute_for_merge_request(merge_request)
2022-06-21 17:19:12 +05:30
merge_request.environments_in_head_pipeline(deployment_status: :success).each do |environment|
execute(environment)
end
2017-08-17 22:00:37 +05:30
end
private
def environments
2021-06-08 01:23:25 +05:30
@environments ||= Environments::EnvironmentsByDeploymentsFinder
2017-08-17 22:00:37 +05:30
.new(project, current_user, ref: @ref, recently_updated: true)
.execute
end
end
end