Commit 5f502c3a authored by Grzegorz Bizon's avatar Grzegorz Bizon

Move external CI config class into proper namespace

parent 7acc6340
......@@ -15,7 +15,7 @@ module Gitlab
@global.compose!
rescue Loader::FormatError, Extendable::ExtensionError => e
raise Config::ConfigError, e.message
rescue ::Gitlab::Ci::External::Processor::FileError => e
rescue External::Processor::FileError => e
raise ::Gitlab::Ci::YamlProcessor::ValidationError, e.message
end
......@@ -81,7 +81,7 @@ module Gitlab
def process_external_files(config, project, opts)
sha = opts.fetch(:sha) { project.repository.root_ref_sha }
::Gitlab::Ci::External::Processor.new(config, project, sha).perform
Config::External::Processor.new(config, project, sha).perform
end
end
end
......
......@@ -2,6 +2,7 @@
module Gitlab
module Ci
class Config
module External
module File
class Base
......@@ -26,4 +27,5 @@ module Gitlab
end
end
end
end
end
......@@ -2,6 +2,7 @@
module Gitlab
module Ci
class Config
module External
module File
class Local < Base
......@@ -31,4 +32,5 @@ module Gitlab
end
end
end
end
end
......@@ -2,6 +2,7 @@
module Gitlab
module Ci
class Config
module External
module File
class Remote < Base
......@@ -27,4 +28,5 @@ module Gitlab
end
end
end
end
end
......@@ -2,6 +2,7 @@
module Gitlab
module Ci
class Config
module External
class Mapper
def initialize(values, project, sha)
......@@ -20,10 +21,10 @@ module Gitlab
def build_external_file(location)
if ::Gitlab::UrlSanitizer.valid?(location)
Gitlab::Ci::External::File::Remote.new(location)
External::File::Remote.new(location)
else
options = { project: project, sha: sha }
Gitlab::Ci::External::File::Local.new(location, options)
External::File::Local.new(location, project: project, sha: sha)
end
end
end
end
......
......@@ -2,13 +2,14 @@
module Gitlab
module Ci
class Config
module External
class Processor
FileError = Class.new(StandardError)
def initialize(values, project, sha)
@values = values
@external_files = Gitlab::Ci::External::Mapper.new(values, project, sha).process
@external_files = External::Mapper.new(values, project, sha).process
@content = {}
end
......@@ -35,7 +36,7 @@ module Gitlab
end
def content_of(external_file)
Gitlab::Ci::Config::Loader.new(external_file.content).load!
Config::Loader.new(external_file.content).load!
end
def append_inline_content
......@@ -49,4 +50,5 @@ module Gitlab
end
end
end
end
end
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe Gitlab::Ci::External::File::Local do
describe Gitlab::Ci::Config::External::File::Local do
let(:project) { create(:project, :repository) }
let(:local_file) { described_class.new(location, { project: project, sha: '12345' }) }
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe Gitlab::Ci::External::File::Remote do
describe Gitlab::Ci::Config::External::File::Remote do
let(:remote_file) { described_class.new(location) }
let(:location) { 'https://gitlab.com/gitlab-org/gitlab-ce/blob/1234/.gitlab-ci-1.yml' }
let(:remote_file_content) do
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe Gitlab::Ci::External::Mapper do
describe Gitlab::Ci::Config::External::Mapper do
let(:project) { create(:project, :repository) }
let(:file_content) do
<<~HEREDOC
......@@ -27,7 +27,8 @@ describe Gitlab::Ci::External::Mapper do
end
it 'returns File instances' do
expect(subject.first).to be_an_instance_of(Gitlab::Ci::External::File::Local)
expect(subject.first)
.to be_an_instance_of(Gitlab::Ci::Config::External::File::Local)
end
end
......@@ -49,7 +50,8 @@ describe Gitlab::Ci::External::Mapper do
end
it 'returns File instances' do
expect(subject.first).to be_an_instance_of(Gitlab::Ci::External::File::Remote)
expect(subject.first)
.to be_an_instance_of(Gitlab::Ci::Config::External::File::Remote)
end
end
end
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe Gitlab::Ci::External::Processor do
describe Gitlab::Ci::Config::External::Processor do
let(:project) { create(:project, :repository) }
let(:processor) { described_class.new(values, project, '12345') }
......@@ -92,7 +92,8 @@ describe Gitlab::Ci::External::Processor do
end
before do
allow_any_instance_of(Gitlab::Ci::External::File::Local).to receive(:fetch_local_content).and_return(local_file_content)
allow_any_instance_of(Gitlab::Ci::Config::External::File::Local)
.to receive(:fetch_local_content).and_return(local_file_content)
end
it 'should append the file to the values' do
......@@ -131,7 +132,10 @@ describe Gitlab::Ci::External::Processor do
before do
local_file_content = File.read(Rails.root.join('spec/fixtures/gitlab/ci/external_files/.gitlab-ci-template-1.yml'))
allow_any_instance_of(Gitlab::Ci::External::File::Local).to receive(:fetch_local_content).and_return(local_file_content)
allow_any_instance_of(Gitlab::Ci::Config::External::File::Local)
.to receive(:fetch_local_content).and_return(local_file_content)
WebMock.stub_request(:get, remote_file).to_return(body: remote_file_content)
end
......@@ -150,7 +154,8 @@ describe Gitlab::Ci::External::Processor do
let(:local_file_content) { 'invalid content file ////' }
before do
allow_any_instance_of(Gitlab::Ci::External::File::Local).to receive(:fetch_local_content).and_return(local_file_content)
allow_any_instance_of(Gitlab::Ci::Config::External::File::Local)
.to receive(:fetch_local_content).and_return(local_file_content)
end
it 'should raise an error' do
......
require 'fast_spec_helper'
require_dependency 'active_model'
require 'spec_helper'
describe Gitlab::Ci::Config do
let(:config) do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment