debian-mirror-gitlab/app/services/groups/update_shared_runners_service.rb

40 lines
1 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module Groups
class UpdateSharedRunnersService < Groups::BaseService
def execute
return error('Operation not allowed', 403) unless can?(current_user, :admin_group, group)
validate_params
2021-01-03 14:25:43 +05:30
update_shared_runners
2021-11-11 11:23:49 +05:30
update_pending_builds!
2020-07-28 23:09:34 +05:30
success
2021-01-03 14:25:43 +05:30
rescue ActiveRecord::RecordInvalid, ArgumentError => error
2020-07-28 23:09:34 +05:30
error(error.message)
end
private
def validate_params
2021-01-03 14:25:43 +05:30
unless Namespace::SHARED_RUNNERS_SETTINGS.include?(params[:shared_runners_setting])
raise ArgumentError, "state must be one of: #{Namespace::SHARED_RUNNERS_SETTINGS.join(', ')}"
2020-07-28 23:09:34 +05:30
end
end
2021-01-03 14:25:43 +05:30
def update_shared_runners
group.update_shared_runners_setting!(params[:shared_runners_setting])
2020-07-28 23:09:34 +05:30
end
2021-11-11 11:23:49 +05:30
def update_pending_builds!
return unless group.previous_changes.include?('shared_runners_enabled')
update_params = { instance_runners_enabled: group.shared_runners_enabled }
::Ci::UpdatePendingBuildService.new(group, update_params).execute
end
2020-07-28 23:09:34 +05:30
end
end