diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /app/graphql/mutations/container_repositories/destroy_tags.rb | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'app/graphql/mutations/container_repositories/destroy_tags.rb')
-rw-r--r-- | app/graphql/mutations/container_repositories/destroy_tags.rb | 50 |
1 files changed, 50 insertions, 0 deletions
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 |