2016-11-08 13:20:58 +00:00
|
|
|
module Ci
|
2016-11-14 12:57:09 +00:00
|
|
|
class StopEnvironmentsService < BaseService
|
2016-11-09 08:42:09 +00:00
|
|
|
attr_reader :ref
|
2016-11-08 13:20:58 +00:00
|
|
|
|
2016-11-09 08:42:09 +00:00
|
|
|
def execute(branch_name)
|
|
|
|
@ref = branch_name
|
|
|
|
|
2016-11-09 13:46:36 +00:00
|
|
|
return unless has_ref?
|
2016-11-08 13:20:58 +00:00
|
|
|
|
|
|
|
environments.each do |environment|
|
|
|
|
next unless environment.stoppable?
|
2016-11-14 12:54:23 +00:00
|
|
|
next unless can?(current_user, :create_deployment, project)
|
2016-11-08 13:20:58 +00:00
|
|
|
|
|
|
|
environment.stop!(current_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-11-09 13:46:36 +00:00
|
|
|
def has_ref?
|
|
|
|
@ref.present?
|
2016-11-08 13:20:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def environments
|
2016-11-16 09:54:20 +00:00
|
|
|
@environments ||= project
|
|
|
|
.environments_recently_updated_on_branch(@ref)
|
2016-11-08 13:20:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|