diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-10-19 16:16:30 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-10-19 16:16:30 +0200 |
commit | 7977a20bb4b095781f0328aff2e5e90f22cf6699 (patch) | |
tree | d516b8fa88463a2a933122979f84119c935ceb12 /lib/gitlab/ci | |
parent | d9780bc0af7afe79f22b22dc6ae6d7392ecf779f (diff) | |
download | gitlab-ce-7977a20bb4b095781f0328aff2e5e90f22cf6699.tar.gz |
Extend error message in case of HTTP errors in `include`
Diffstat (limited to 'lib/gitlab/ci')
-rw-r--r-- | lib/gitlab/ci/config/external/file/base.rb | 14 | ||||
-rw-r--r-- | lib/gitlab/ci/config/external/file/local.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/config/external/file/remote.rb | 32 |
3 files changed, 28 insertions, 20 deletions
diff --git a/lib/gitlab/ci/config/external/file/base.rb b/lib/gitlab/ci/config/external/file/base.rb index 390db997c0b..d02dac66f93 100644 --- a/lib/gitlab/ci/config/external/file/base.rb +++ b/lib/gitlab/ci/config/external/file/base.rb @@ -17,9 +17,7 @@ module Gitlab @opts = opts @errors = [] - validate_location! - validate_content! - validate_hash! + validate! end def invalid_extension? @@ -46,6 +44,12 @@ module Gitlab protected + def validate! + validate_location! + validate_content! if errors.none? + validate_hash! if errors.none? + end + def validate_location! if invalid_extension? errors.push("Included file `#{location}` does not have YAML extension!") @@ -53,13 +57,13 @@ module Gitlab end def validate_content! - if errors.none? && content.blank? + if content.blank? errors.push("Included file `#{location}` is empty or does not exist!") end end def validate_hash! - if errors.none? && to_hash.blank? + if to_hash.blank? errors.push("Included file `#{location}` does not have valid YAML syntax!") end end diff --git a/lib/gitlab/ci/config/external/file/local.rb b/lib/gitlab/ci/config/external/file/local.rb index acf4201a672..2a256aff65c 100644 --- a/lib/gitlab/ci/config/external/file/local.rb +++ b/lib/gitlab/ci/config/external/file/local.rb @@ -24,8 +24,6 @@ module Gitlab private def validate_content! - return if errors.any? - if content.nil? errors.push("Local file `#{location}` does not exist!") elsif content.blank? diff --git a/lib/gitlab/ci/config/external/file/remote.rb b/lib/gitlab/ci/config/external/file/remote.rb index b1ba37a3959..23dfc5d9d44 100644 --- a/lib/gitlab/ci/config/external/file/remote.rb +++ b/lib/gitlab/ci/config/external/file/remote.rb @@ -23,19 +23,25 @@ module Gitlab end def fetch_remote_content - Gitlab::HTTP.get(location) - rescue SocketError - errors.push("Remote file `#{location}` could not be fetched because of a socket error!") - nil - rescue Timeout::Error - errors.push("Remote file `#{location}` could not be fetched because of a timeout error!") - nil - rescue Gitlab::HTTP::Error - errors.push("Remote file `#{location}` could not be fetched because of a HTTP error!") - nil - rescue Gitlab::HTTP::BlockedUrlError - errors.push("Remote file `#{location}` could not be fetched because the URL is blocked!") - nil + begin + response = Gitlab::HTTP.get(location) + rescue SocketError + errors.push("Remote file `#{location}` could not be fetched because of a socket error!") + rescue Timeout::Error + errors.push("Remote file `#{location}` could not be fetched because of a timeout error!") + rescue Gitlab::HTTP::Error + errors.push("Remote file `#{location}` could not be fetched because of HTTP error!") + rescue Gitlab::HTTP::BlockedUrlError + errors.push("Remote file `#{location}` could not be fetched because the URL is blocked!") + end + + if response&.code.to_i >= 400 + errors.push <<~ERROR + Remote file `#{location}` could not be fetched because of HTTP code `#{response.code}` error! + ERROR + end + + response.to_s if errors.none? end end end |