Commit e0830a74 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Extract method that fetchesremote CI/CD included config

parent 2243f0e3
...@@ -10,20 +10,20 @@ module Gitlab ...@@ -10,20 +10,20 @@ module Gitlab
attr_reader :location attr_reader :location
def content def content
return @content if defined?(@content) strong_memoize(:content) { fetch_remote_content }
@content = strong_memoize(:content) do
begin
Gitlab::HTTP.get(location)
rescue Gitlab::HTTP::Error, Timeout::Error, SocketError, Gitlab::HTTP::BlockedUrlError
nil
end
end
end end
def error_message def error_message
"Remote file '#{location}' is not valid." "Remote file '#{location}' is not valid."
end end
private
def fetch_remote_content
Gitlab::HTTP.get(location)
rescue Gitlab::HTTP::Error, Timeout::Error, SocketError, Gitlab::HTTP::BlockedUrlError
nil
end
end end
end end
end end
......
...@@ -6,7 +6,6 @@ module Gitlab ...@@ -6,7 +6,6 @@ module Gitlab
module External module External
class Processor class Processor
IncludeError = Class.new(StandardError) IncludeError = Class.new(StandardError)
FileError = Class.new(IncludeError)
def initialize(values, project, sha) def initialize(values, project, sha)
@values = values @values = values
...@@ -32,7 +31,7 @@ module Gitlab ...@@ -32,7 +31,7 @@ module Gitlab
def validate_external_file(external_file) def validate_external_file(external_file)
unless external_file.valid? unless external_file.valid?
raise FileError, external_file.error_message raise IncludeError, external_file.error_message
end end
end end
......
...@@ -20,7 +20,7 @@ describe Gitlab::Ci::Config::External::Processor do ...@@ -20,7 +20,7 @@ describe Gitlab::Ci::Config::External::Processor do
it 'should raise an error' do it 'should raise an error' do
expect { processor.perform }.to raise_error( expect { processor.perform }.to raise_error(
described_class::FileError, described_class::IncludeError,
"Local file '/lib/gitlab/ci/templates/non-existent-file.yml' is not valid." "Local file '/lib/gitlab/ci/templates/non-existent-file.yml' is not valid."
) )
end end
...@@ -36,7 +36,7 @@ describe Gitlab::Ci::Config::External::Processor do ...@@ -36,7 +36,7 @@ describe Gitlab::Ci::Config::External::Processor do
it 'should raise an error' do it 'should raise an error' do
expect { processor.perform }.to raise_error( expect { processor.perform }.to raise_error(
described_class::FileError, described_class::IncludeError,
"Remote file '#{remote_file}' is not valid." "Remote file '#{remote_file}' is not valid."
) )
end end
......
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