Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-12-20 16:37:47 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-12-20 16:37:47 +0300
commitaee0a117a889461ce8ced6fcf73207fe017f1d99 (patch)
tree891d9ef189227a8445d83f35c1b0fc99573f4380 /app/graphql/resolvers/container_repository_tags_resolver.rb
parent8d46af3258650d305f53b819eabf7ab18d22f59e (diff)
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'app/graphql/resolvers/container_repository_tags_resolver.rb')
-rw-r--r--app/graphql/resolvers/container_repository_tags_resolver.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/app/graphql/resolvers/container_repository_tags_resolver.rb b/app/graphql/resolvers/container_repository_tags_resolver.rb
new file mode 100644
index 00000000000..55a83dd49da
--- /dev/null
+++ b/app/graphql/resolvers/container_repository_tags_resolver.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+
+module Resolvers
+ class ContainerRepositoryTagsResolver < BaseResolver
+ type Types::ContainerRepositoryTagType.connection_type, null: true
+
+ argument :sort, Types::ContainerRepositoryTagsSortEnum,
+ description: 'Sort tags by these criteria.',
+ required: false,
+ default_value: nil
+
+ argument :name, GraphQL::Types::String,
+ description: 'Search by tag name.',
+ required: false,
+ default_value: nil
+
+ def resolve(sort:, **filters)
+ result = tags
+
+ if filters[:name]
+ result = tags.filter do |tag|
+ tag.name.include?(filters[:name])
+ end
+ end
+
+ result = sort_tags(result, sort) if sort
+ result
+ end
+
+ private
+
+ def sort_tags(to_be_sorted, sort)
+ raise StandardError unless Types::ContainerRepositoryTagsSortEnum.enum.include?(sort)
+
+ sort_value, _, direction = sort.to_s.rpartition('_')
+
+ sorted = to_be_sorted.sort_by(&sort_value.to_sym)
+ return sorted.reverse if direction == 'desc'
+
+ sorted
+ end
+
+ def tags
+ object.tags
+ rescue Faraday::Error
+ raise ::Gitlab::Graphql::Errors::ResourceNotAvailable, "Can't connect to the Container Registry. If this error persists, please review the troubleshooting documentation."
+ end
+ end
+end