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

34 lines
785 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)
environment.stop_with_action!(current_user)
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)
2021-10-27 15:23:28 +05:30
merge_request.environments.each { |environment| execute(environment) }
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