Class: Ci::SafeDisablePipelineVariablesService
- Inherits:
-
BaseService
- Object
- BaseService
- Ci::SafeDisablePipelineVariablesService
- Defined in:
- app/services/ci/safe_disable_pipeline_variables_service.rb
Constant Summary collapse
- PROJECTS_BATCH_SIZE =
500
Constants inherited from BaseService
BaseService::UnauthorizedError
Instance Attribute Summary
Attributes inherited from BaseService
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(current_user:, group:) ⇒ SafeDisablePipelineVariablesService
constructor
A new instance of SafeDisablePipelineVariablesService.
Methods included from BaseServiceUtility
#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level
Methods included from Gitlab::Allowable
Constructor Details
#initialize(current_user:, group:) ⇒ SafeDisablePipelineVariablesService
Returns a new instance of SafeDisablePipelineVariablesService.
7 8 9 10 |
# File 'app/services/ci/safe_disable_pipeline_variables_service.rb', line 7 def initialize(current_user:, group:) @current_user = current_user @parent_group = group end |
Instance Method Details
#execute ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/services/ci/safe_disable_pipeline_variables_service.rb', line 12 def execute return ServiceResponse.error(message: 'You are not authorized to perform this action') unless updated_count = 0 total_projects_with_pipeline_variables = 0 parent_group.self_and_descendants.each_batch do |group_batch| all_projects_ci_cd_settings = ProjectCiCdSetting.for_namespace(group_batch) .with_pipeline_variables_enabled total_projects_with_pipeline_variables += all_projects_ci_cd_settings.count all_projects_ci_cd_settings .each_batch(of: PROJECTS_BATCH_SIZE) do |ci_cd_settings| batch_updated_count = ProjectCiCdSetting.bulk_restrict_pipeline_variables!( project_ids: ProjectCiCdSetting.project_ids_not_using_variables(ci_cd_settings, PROJECTS_BATCH_SIZE) ) updated_count += batch_updated_count end end skipped_count = total_projects_with_pipeline_variables - updated_count ServiceResponse.success(payload: { updated_count: updated_count, skipped_count: skipped_count }) end |