Class: Gitlab::BackgroundMigration::RemoteDevelopment::WorkspaceOperations::Create::DesiredConfig::BmMain

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/background_migration/remote_development/workspace_operations/create/desired_config/bm_main.rb

Overview

rubocop:disable Migration/BatchedMigrationBaseClass – This is not a migration file class so we do not need to inherit from BatchedMigrationJob

Class Method Summary collapse

Class Method Details

.main(parent_context) ⇒ Hash

Parameters:

  • parent_context (Hash)

Returns:

  • (Hash)


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
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/gitlab/background_migration/remote_development/workspace_operations/create/desired_config/bm_main.rb', line 12

def self.main(parent_context) # rubocop:disable Metrics/MethodLength -- this is a won't fix
  parent_context => {
    params: params,
    workspace: workspace,
    logger: logger
  }

  context = {
    workspace_id: workspace.id,
    workspace_name: workspace.name,
    workspace_namespace: workspace.namespace,
    workspace_desired_state_is_running: workspace.desired_state_running?,
    workspaces_agent_id: params[:agent].id,
    workspaces_agent_config: workspace.workspaces_agent_config,
    processed_devfile_yaml: workspace.processed_devfile,
    logger: logger,
    desired_config_array: []
  }

  initial_result = Gitlab::Fp::Result.ok(context)

  result =
    initial_result
      .map(BmConfigValuesExtractor.method(:extract))
      .map(BmDevfileParserGetter.method(:get))
      .map(BmDesiredConfigYamlParser.method(:parse))
      .map(BmDevfileResourceModifier.method(:modify))
      .map(BmDevfileResourceAppender.method(:append))
      .map(
        ->(context) do
          context.merge(
            desired_config:
              RemoteDevelopment::WorkspaceOperations::BmDesiredConfig.new(
                desired_config_array: context.fetch(:desired_config_array)
              )
          )
        end
      )

  parent_context[:desired_config] = result.unwrap.fetch(:desired_config)

  parent_context
end