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