Class: Ci::SafeDisablePipelineVariablesService

Inherits:
BaseService
  • Object
show all
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

#params, #project

Instance Method Summary collapse

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

#can?, #can_all?, #can_any?

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

#executeObject



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 authorized?

  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