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

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
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.



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

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

  assign_valid_attributes if valid?
end

Instance Attribute Details

#ci_configObject (readonly)

Returns the value of attribute ci_config.



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

def ci_config
  @ci_config
end

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

#jobsObject (readonly)

Returns the value of attribute jobs.



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

def jobs
  @jobs
end

#root_variablesObject (readonly)

Returns the value of attribute root_variables.



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

def root_variables
  @root_variables
end

#root_variables_with_prefill_dataObject (readonly)

Returns the value of attribute root_variables_with_prefill_data.



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

def root_variables_with_prefill_data
  @root_variables_with_prefill_data
end

#stagesObject (readonly)

Returns the value of attribute stages.



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

def stages
  @stages
end

#warningsObject (readonly)

Returns the value of attribute warnings.



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

def warnings
  @warnings
end

#workflow_auto_cancelObject (readonly)

Returns the value of attribute workflow_auto_cancel.



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

def workflow_auto_cancel
  @workflow_auto_cancel
end

#workflow_nameObject (readonly)

Returns the value of attribute workflow_name.



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

def workflow_name
  @workflow_name
end

#workflow_rulesObject (readonly)

Returns the value of attribute workflow_rules.



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

def workflow_rules
  @workflow_rules
end

Instance Method Details

#buildsObject



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

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

#clear_jobs!Object



99
100
101
# File 'lib/gitlab/ci/yaml_processor/result.rb', line 99

def clear_jobs!
  @jobs = {}
end

#config_metadataObject



95
96
97
# File 'lib/gitlab/ci/yaml_processor/result.rb', line 95

def 
  @ci_config&. || {}
end

#included_componentsObject



74
75
76
# File 'lib/gitlab/ci/yaml_processor/result.rb', line 74

def included_components
  @ci_config.included_components
end

#included_templatesObject



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

def included_templates
  @included_templates ||= @ci_config.included_templates
end

#stage_for(job_name) ⇒ Object



91
92
93
# File 'lib/gitlab/ci/yaml_processor/result.rb', line 91

def stage_for(job_name)
  jobs.dig(job_name, :stage)
end

#stages_attributesObject



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

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

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

#uses_input_rules?Boolean

Returns:

  • (Boolean)


65
66
67
68
69
70
71
72
# File 'lib/gitlab/ci/yaml_processor/result.rb', line 65

def uses_input_rules?
  return false unless @ci_config

  inputs = @ci_config.spec[:inputs]
  return false unless inputs.is_a?(Hash)

  inputs.values.any? { |input_spec| input_spec.is_a?(Hash) && input_spec.key?(:rules) }
end

#uses_inputs?Boolean

Returns:

  • (Boolean)


59
60
61
62
63
# File 'lib/gitlab/ci/yaml_processor/result.rb', line 59

def uses_inputs?
  return false unless @ci_config

  @ci_config.spec[:inputs].present?
end

#uses_keyword?(keyword) ⇒ Boolean

Returns:

  • (Boolean)


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

def uses_keyword?(keyword)
  jobs.values.any? do |job|
    job.key?(keyword)
  end
end

#uses_nested_keyword?(path) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
# File 'lib/gitlab/ci/yaml_processor/result.rb', line 53

def uses_nested_keyword?(path)
  jobs.values.any? do |job|
    has_nested_key?(job, *path)
  end
end

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  errors.empty?
end

#yaml_variables_for(job_name) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/gitlab/ci/yaml_processor/result.rb', line 79

def yaml_variables_for(job_name)
  job = jobs[job_name]

  return [] unless job

  Gitlab::Ci::Variables::Helpers.inherit_yaml_variables(
    from: root_variables,
    to: job[:job_variables],
    inheritance: job.fetch(:root_variables_inheritance, true)
  )
end