Skip to content
Snippets Groups Projects
Commit d501850e authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Add gitlab ci configuration class that holds hash

As for now, we keep this class inside a oryginal config processor class.
We will move implementation to this class and delegate to it from
current config processor.

After original gitlab ci yaml processor not longer has relevant
impelemntation we will replace it with new configuration class.
parent 3f4ac2ff
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -12,18 +12,14 @@ module Ci
attr_reader :before_script, :after_script, :image, :services, :path, :cache
 
def initialize(config, path = nil)
@config = YAML.safe_load(config, [Symbol], [], true)
@config = Gitlab::Ci::Config.new(config).to_hash
@path = path
 
unless @config.is_a? Hash
raise ValidationError, "YAML should be a hash"
end
@config = @config.deep_symbolize_keys
initial_parsing
 
validate!
rescue Gitlab::Ci::Config::ParserError => e
raise ValidationError, e.message
end
 
def builds_for_stage_and_ref(stage, ref, tag = false, trigger_request = nil)
Loading
Loading
module Gitlab
module Ci
class Config
class ParserError < StandardError; end
def initialize(config)
@config = YAML.safe_load(config, [Symbol], [], true)
unless @config.is_a?(Hash)
raise ParserError, 'YAML should be a hash'
end
@config = @config.deep_symbolize_keys
end
def to_hash
@config
end
end
end
end
require 'spec_helper'
describe Gitlab::Ci::Config do
let(:config) do
described_class.new(yml)
end
context 'when yml config is valid' do
let(:yml) do
<<-EOS
image: ruby:2.2
rspec:
script:
- gem install rspec
- rspec
EOS
end
describe '#to_hash' do
it 'returns hash created from string' do
hash = {
image: 'ruby:2.2',
rspec: {
script: ['gem install rspec',
'rspec']
}
}
expect(config.to_hash).to eq hash
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment