diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-16 18:06:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-16 18:06:47 +0300 |
commit | cb8835f38a3e4c188e9a73adf45936e2a95f40ae (patch) | |
tree | 60c25b80fbcf5deb25b9bb00539564b8296858f6 /lib | |
parent | 218585fc850159e0cf7fa4b609f0837cb5f29599 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bitbucket/connection.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/ci/config/interpolation/text_interpolator.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/ci/config/yaml/documents.rb | 57 | ||||
-rw-r--r-- | lib/gitlab/config/loader/yaml.rb | 3 |
4 files changed, 66 insertions, 10 deletions
diff --git a/lib/bitbucket/connection.rb b/lib/bitbucket/connection.rb index f28b2a0a899..e7bd8706a64 100644 --- a/lib/bitbucket/connection.rb +++ b/lib/bitbucket/connection.rb @@ -24,13 +24,9 @@ module Bitbucket def get(path, extra_query = {}) refresh! if expired? - response = if Feature.enabled?(:bitbucket_importer_exponential_backoff) - retry_with_exponential_backoff do - connection.get(build_url(path), params: @default_query.merge(extra_query)) - end - else - connection.get(build_url(path), params: @default_query.merge(extra_query)) - end + response = retry_with_exponential_backoff do + connection.get(build_url(path), params: @default_query.merge(extra_query)) + end response.parsed end diff --git a/lib/gitlab/ci/config/interpolation/text_interpolator.rb b/lib/gitlab/ci/config/interpolation/text_interpolator.rb index 5c4953f8bbe..f5c83023f92 100644 --- a/lib/gitlab/ci/config/interpolation/text_interpolator.rb +++ b/lib/gitlab/ci/config/interpolation/text_interpolator.rb @@ -37,14 +37,14 @@ module Gitlab end def interpolate! - return errors.push(config.error) unless config.valid? + return errors.concat(config.errors) unless config.valid? if inputs_without_header? return errors.push( _('Given inputs not defined in the `spec` section of the included configuration file')) end - return @result ||= config.content unless config.has_header? + return @result ||= config.content unless config.header return errors.concat(header.errors) unless header.valid? return errors.concat(inputs.errors) unless inputs.valid? @@ -65,7 +65,7 @@ module Gitlab attr_reader :config, :input_args, :variables def inputs_without_header? - input_args.any? && !config.has_header? + input_args.any? && !config.header end def header diff --git a/lib/gitlab/ci/config/yaml/documents.rb b/lib/gitlab/ci/config/yaml/documents.rb new file mode 100644 index 00000000000..04a31da8a2e --- /dev/null +++ b/lib/gitlab/ci/config/yaml/documents.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +module Gitlab + module Ci + class Config + module Yaml + class Documents + include Gitlab::Utils::StrongMemoize + + attr_reader :errors + + def initialize(documents) + @documents = documents + @errors = [] + + parsed_first_document + end + + def valid? + errors.none? + end + + def header + return unless has_header? + + parsed_first_document + end + + def content + return documents.last.raw if has_header? + + documents.first&.raw || '' + end + + private + + attr_reader :documents + + def has_header? + return false unless parsed_first_document.is_a?(Hash) + + documents.count > 1 && parsed_first_document.key?(:spec) + end + + def parsed_first_document + return {} if documents.count == 0 + + documents.first.load! + rescue ::Gitlab::Config::Loader::FormatError => e + errors << e.message + end + strong_memoize_attr :parsed_first_document + end + end + end + end +end diff --git a/lib/gitlab/config/loader/yaml.rb b/lib/gitlab/config/loader/yaml.rb index 7138663811e..647be42fa59 100644 --- a/lib/gitlab/config/loader/yaml.rb +++ b/lib/gitlab/config/loader/yaml.rb @@ -13,7 +13,10 @@ module Gitlab include Gitlab::Utils::StrongMemoize + attr_reader :raw + def initialize(config, additional_permitted_classes: []) + @raw = config @config = YAML.safe_load(config, permitted_classes: [Symbol, *additional_permitted_classes], permitted_symbols: [], |