2020-12-08 03:09:37 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module ContainerRepositories
|
|
|
|
class DestroyTags < ::Mutations::ContainerRepositories::DestroyBase
|
2021-03-26 03:09:21 +00:00
|
|
|
LIMIT = 20
|
2020-12-08 03:09:37 +00:00
|
|
|
|
|
|
|
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],
|
2021-01-07 12:10:24 +00:00
|
|
|
description: 'Deleted container repository tags.',
|
2020-12-08 03:09:37 +00:00
|
|
|
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
|