diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-10 12:11:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-10 12:11:07 +0300 |
commit | 16e3c17d3f24314a7a4dfd3c7189701eeb40bf16 (patch) | |
tree | 2da0fa39326060f30b468570b396904bc4ec29b7 /lib/gitlab | |
parent | ff2b80a5548b308f31acce94069bb3fd2e0480c3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/ci/variables/collection.rb | 13 | ||||
-rw-r--r-- | lib/gitlab/ci/variables/collection/sort.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/graphql/loaders/full_path_model_loader.rb | 5 |
3 files changed, 13 insertions, 7 deletions
diff --git a/lib/gitlab/ci/variables/collection.rb b/lib/gitlab/ci/variables/collection.rb index ef9ba1b73c7..73d27399680 100644 --- a/lib/gitlab/ci/variables/collection.rb +++ b/lib/gitlab/ci/variables/collection.rb @@ -10,7 +10,7 @@ module Gitlab def initialize(variables = [], errors = nil) @variables = [] - @variables_by_key = {} + @variables_by_key = Hash.new { |h, k| h[k] = [] } @errors = errors variables.each { |variable| self.append(variable) } @@ -19,7 +19,7 @@ module Gitlab def append(resource) item = Collection::Item.fabricate(resource) @variables.append(item) - @variables_by_key[item[:key]] = item + @variables_by_key[item[:key]] << item self end @@ -46,7 +46,12 @@ module Gitlab end def [](key) - @variables_by_key[key] + all(key)&.last + end + + def all(key) + vars = @variables_by_key[key] + vars unless vars.empty? end def size @@ -72,7 +77,7 @@ module Gitlab match = Regexp.last_match if match[:key] # we matched variable - if variable = @variables_by_key[match[:key]] + if variable = self[match[:key]] variable.value elsif keep_undefined match[0] diff --git a/lib/gitlab/ci/variables/collection/sort.rb b/lib/gitlab/ci/variables/collection/sort.rb index 90a929b8a07..62637825c15 100644 --- a/lib/gitlab/ci/variables/collection/sort.rb +++ b/lib/gitlab/ci/variables/collection/sort.rb @@ -42,7 +42,7 @@ module Gitlab depends_on = var_item.depends_on return unless depends_on - depends_on.filter_map { |var_ref_name| @collection[var_ref_name] }.each(&block) + depends_on.filter_map { |var_ref_name| @collection.all(var_ref_name) }.flatten.each(&block) end end end diff --git a/lib/gitlab/graphql/loaders/full_path_model_loader.rb b/lib/gitlab/graphql/loaders/full_path_model_loader.rb index 26c1ce64a83..7f9013c6e4c 100644 --- a/lib/gitlab/graphql/loaders/full_path_model_loader.rb +++ b/lib/gitlab/graphql/loaders/full_path_model_loader.rb @@ -5,19 +5,20 @@ module Gitlab module Loaders # Suitable for use to find resources that expose `where_full_path_in`, # such as Project, Group, Namespace + # full path is always converted to lowercase for case-insensitive results class FullPathModelLoader attr_reader :model_class, :full_path def initialize(model_class, full_path) @model_class = model_class - @full_path = full_path + @full_path = full_path.downcase end def find BatchLoader::GraphQL.for(full_path).batch(key: model_class) do |full_paths, loader, args| # `with_route` avoids an N+1 calculating full_path args[:key].where_full_path_in(full_paths).with_route.each do |model_instance| - loader.call(model_instance.full_path, model_instance) + loader.call(model_instance.full_path.downcase, model_instance) end end end |