diff options
Diffstat (limited to 'app/graphql/mutations/container_repositories')
3 files changed, 69 insertions, 12 deletions
diff --git a/app/graphql/mutations/container_repositories/destroy.rb b/app/graphql/mutations/container_repositories/destroy.rb index 8312193147f..90fba66e7b3 100644 --- a/app/graphql/mutations/container_repositories/destroy.rb +++ b/app/graphql/mutations/container_repositories/destroy.rb @@ -2,9 +2,7 @@ module Mutations module ContainerRepositories - class Destroy < Mutations::BaseMutation - include ::Mutations::PackageEventable - + class Destroy < ::Mutations::ContainerRepositories::DestroyBase graphql_name 'DestroyContainerRepository' authorize :destroy_container_image @@ -31,15 +29,6 @@ module Mutations errors: [] } end - - private - - def find_object(id:) - # TODO: remove this line when the compatibility layer is removed - # See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883 - id = ::Types::GlobalIDType[::ContainerRepository].coerce_isolated_input(id) - GitlabSchema.find_by_gid(id) - end end end end diff --git a/app/graphql/mutations/container_repositories/destroy_base.rb b/app/graphql/mutations/container_repositories/destroy_base.rb new file mode 100644 index 00000000000..ddaa6c52121 --- /dev/null +++ b/app/graphql/mutations/container_repositories/destroy_base.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Mutations + module ContainerRepositories + class DestroyBase < Mutations::BaseMutation + include ::Mutations::PackageEventable + + private + + def find_object(id:) + # TODO: remove this line when the compatibility layer is removed + # See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883 + id = ::Types::GlobalIDType[::ContainerRepository].coerce_isolated_input(id) + GitlabSchema.find_by_gid(id) + end + end + end +end diff --git a/app/graphql/mutations/container_repositories/destroy_tags.rb b/app/graphql/mutations/container_repositories/destroy_tags.rb new file mode 100644 index 00000000000..ca6a67867c3 --- /dev/null +++ b/app/graphql/mutations/container_repositories/destroy_tags.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +module Mutations + module ContainerRepositories + class DestroyTags < ::Mutations::ContainerRepositories::DestroyBase + LIMIT = 20.freeze + + TOO_MANY_TAGS_ERROR_MESSAGE = "Number of tags is greater than #{LIMIT}" + + graphql_name 'DestroyContainerRepositoryTags' + + authorize :destroy_container_image + + argument :id, + ::Types::GlobalIDType[::ContainerRepository], + required: true, + description: 'ID of the container repository.' + + argument :tag_names, + [GraphQL::STRING_TYPE], + required: true, + description: "Container repository tag(s) to delete. Total number can't be greater than #{LIMIT}", + prepare: ->(tag_names, _) do + raise Gitlab::Graphql::Errors::ArgumentError, TOO_MANY_TAGS_ERROR_MESSAGE if tag_names.size > LIMIT + + tag_names + end + + field :deleted_tag_names, + [GraphQL::STRING_TYPE], + description: 'Deleted container repository tags', + null: false + + def resolve(id:, tag_names:) + container_repository = authorized_find!(id: id) + + result = ::Projects::ContainerRepository::DeleteTagsService + .new(container_repository.project, current_user, tags: tag_names) + .execute(container_repository) + + track_event(:delete_tag_bulk, :tag) if result[:status] == :success + + { + errors: Array(result[:message]), + deleted_tag_names: result[:deleted] || [] + } + end + end + end +end |