Commit 0426d15c authored by Giorgenes Gelatti's avatar Giorgenes Gelatti Committed by Nathan Friend

Support bulk registry tag delete

parent 15bda06c
...@@ -28,6 +28,21 @@ module Projects ...@@ -28,6 +28,21 @@ module Projects
end end
end end
def bulk_destroy
@tags = (params[:ids] || []).map { |tag_name| image.tag(tag_name) }
success_count = 0
@tags.each do |tag|
if tag.delete
success_count += 1
end
end
respond_to do |format|
format.json { head(success_count == @tags.size ? :no_content : :bad_request) }
end
end
private private
def tags def tags
......
...@@ -474,7 +474,11 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -474,7 +474,11 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
# in JSON format, or a request for tag named `latest.json`. # in JSON format, or a request for tag named `latest.json`.
scope format: false do scope format: false do
resources :tags, only: [:index, :destroy], resources :tags, only: [:index, :destroy],
constraints: { id: Gitlab::Regex.container_registry_tag_regex } constraints: { id: Gitlab::Regex.container_registry_tag_regex } do
collection do
delete :bulk_destroy
end
end
end end
end end
end end
......
...@@ -113,4 +113,37 @@ describe Projects::Registry::TagsController do ...@@ -113,4 +113,37 @@ describe Projects::Registry::TagsController do
format: :json format: :json
end end
end end
describe 'POST bulk_destroy' do
context 'when user has access to registry' do
before do
project.add_developer(user)
end
context 'when there is matching tag present' do
before do
stub_container_registry_tags(repository: repository.path, tags: %w[rc1 test.])
end
it 'makes it possible to delete tags in bulk' do
allow_any_instance_of(ContainerRegistry::Tag).to receive(:delete) { |*args| ContainerRegistry::Tag.delete(*args) }
expect(ContainerRegistry::Tag).to receive(:delete).exactly(2).times
bulk_destroy_tags(['rc1', 'test.'])
end
end
end
private
def bulk_destroy_tags(names)
post :bulk_destroy, params: {
namespace_id: project.namespace,
project_id: project,
repository_id: repository,
ids: names
},
format: :json
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment