Class: Gitlab::Ci::YamlProcessor::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/yaml_processor/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ci_config: nil, errors: [], warnings: []) ⇒ Result

Returns a new instance of Result.


11
12
13
14
15
# File 'lib/gitlab/ci/yaml_processor/result.rb', line 11

def initialize(ci_config: nil, errors: [], warnings: [])
  @ci_config = ci_config
  @errors = errors || []
  @warnings = warnings || []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors


9
10
11
# File 'lib/gitlab/ci/yaml_processor/result.rb', line 9

def errors
  @errors
end

#warningsObject (readonly)

Returns the value of attribute warnings


9
10
11
# File 'lib/gitlab/ci/yaml_processor/result.rb', line 9

def warnings
  @warnings
end

Instance Method Details

#build_attributes(name) ⇒ Object


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/gitlab/ci/yaml_processor/result.rb', line 56

def build_attributes(name)
  job = jobs.fetch(name.to_sym, {})

  { stage_idx: stages.index(job[:stage]),
    stage: job[:stage],
    tag_list: job[:tags],
    name: job[:name].to_s,
    allow_failure: job[:ignore],
    when: job[:when] || 'on_success',
    environment: job[:environment_name],
    coverage_regex: job[:coverage],
    yaml_variables: transform_to_yaml_variables(job[:variables]),
    needs_attributes: job.dig(:needs, :job),
    interruptible: job[:interruptible],
    only: job[:only],
    except: job[:except],
    rules: job[:rules],
    cache: job[:cache],
    resource_group_key: job[:resource_group],
    scheduling_type: job[:scheduling_type],
    secrets: job[:secrets],
    options: {
      image: job[:image],
      services: job[:services],
      artifacts: job[:artifacts],
      dependencies: job[:dependencies],
      cross_dependencies: job.dig(:needs, :cross_dependency),
      job_timeout: job[:timeout],
      before_script: job[:before_script],
      script: job[:script],
      after_script: job[:after_script],
      environment: job[:environment],
      retry: job[:retry],
      parallel: job[:parallel],
      instance: job[:instance],
      start_in: job[:start_in],
      trigger: job[:trigger],
      bridge_needs: job.dig(:needs, :bridge)&.first,
      release: release(job)
    }.compact }.compact
end

#buildsObject


29
30
31
32
33
# File 'lib/gitlab/ci/yaml_processor/result.rb', line 29

def builds
  jobs.map do |name, _|
    build_attributes(name)
  end
end

#jobsObject


48
49
50
# File 'lib/gitlab/ci/yaml_processor/result.rb', line 48

def jobs
  @jobs ||= @ci_config.normalized_jobs
end

#stage_builds_attributes(stage) ⇒ Object


35
36
37
38
39
# File 'lib/gitlab/ci/yaml_processor/result.rb', line 35

def stage_builds_attributes(stage)
  jobs.values
    .select { |job| job[:stage] == stage }
    .map { |job| build_attributes(job[:name]) }
end

#stagesObject


52
53
54
# File 'lib/gitlab/ci/yaml_processor/result.rb', line 52

def stages
  @stages ||= @ci_config.stages
end

#stages_attributesObject


21
22
23
24
25
26
27
# File 'lib/gitlab/ci/yaml_processor/result.rb', line 21

def stages_attributes
  stages.uniq.map do |stage|
    seeds = stage_builds_attributes(stage)

    { name: stage, index: stages.index(stage), builds: seeds }
  end
end

#valid?Boolean

Returns:

  • (Boolean)

17
18
19
# File 'lib/gitlab/ci/yaml_processor/result.rb', line 17

def valid?
  errors.empty?
end

#workflow_attributesObject


41
42
43
44
45
46
# File 'lib/gitlab/ci/yaml_processor/result.rb', line 41

def workflow_attributes
  {
    rules: hash_config.dig(:workflow, :rules),
    yaml_variables: transform_to_yaml_variables(variables)
  }
end