Class: Gitlab::Ci::YamlProcessor

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

Defined Under Namespace

Classes: Result

Constant Summary collapse

ValidationError =
Class.new(StandardError)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_content, opts = {}) ⇒ YamlProcessor

Returns a new instance of YamlProcessor.


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

def initialize(config_content, opts = {})
  @config_content = config_content
  @opts = opts
end

Class Method Details

.validation_message(content, opts = {}) ⇒ Object


13
14
15
16
17
# File 'lib/gitlab/ci/yaml_processor.rb', line 13

def self.validation_message(content, opts = {})
  result = new(content, opts).execute

  result.errors.first
end

Instance Method Details

#executeObject


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gitlab/ci/yaml_processor.rb', line 24

def execute
  if @config_content.blank?
    return Result.new(errors: ['Please provide content of .gitlab-ci.yml'])
  end

  @ci_config = Gitlab::Ci::Config.new(@config_content, **@opts)

  unless @ci_config.valid?
    return Result.new(ci_config: @ci_config, errors: @ci_config.errors, warnings: @ci_config.warnings)
  end

  run_logical_validations!

  Result.new(ci_config: @ci_config, warnings: @ci_config&.warnings)

rescue Gitlab::Ci::Config::ConfigError => e
  Result.new(ci_config: @ci_config, errors: [e.message], warnings: @ci_config&.warnings)

rescue ValidationError => e
  Result.new(ci_config: @ci_config, errors: [e.message], warnings: @ci_config&.warnings)
end