summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/concerns/storage/legacy_namespace.rb6
-rw-r--r--app/models/namespace.rb4
-rw-r--r--changelogs/unreleased/sh-improve-container-tags-update-username.yml5
-rw-r--r--spec/models/namespace_spec.rb24
4 files changed, 36 insertions, 3 deletions
diff --git a/app/models/concerns/storage/legacy_namespace.rb b/app/models/concerns/storage/legacy_namespace.rb
index 9785011720a..7723c07279d 100644
--- a/app/models/concerns/storage/legacy_namespace.rb
+++ b/app/models/concerns/storage/legacy_namespace.rb
@@ -5,8 +5,10 @@ module Storage
extend ActiveSupport::Concern
def move_dir
- if any_project_has_container_registry_tags?
- raise Gitlab::UpdatePathError.new('Namespace cannot be moved, because at least one project has tags in container registry')
+ proj_with_tags = first_project_with_container_registry_tags
+
+ if proj_with_tags
+ raise Gitlab::UpdatePathError.new("Namespace #{name} (#{id}) cannot be moved because at least one project (e.g. #{proj_with_tags.name} (#{proj_with_tags.id})) has tags in container registry")
end
parent_was = if parent_changed? && parent_id_was.present?
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index c54be778d1b..599bedde27d 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -135,6 +135,10 @@ class Namespace < ActiveRecord::Base
all_projects.any?(&:has_container_registry_tags?)
end
+ def first_project_with_container_registry_tags
+ all_projects.find(&:has_container_registry_tags?)
+ end
+
def send_update_instructions
projects.each do |project|
project.send_move_instructions("#{full_path_was}/#{project.path}")
diff --git a/changelogs/unreleased/sh-improve-container-tags-update-username.yml b/changelogs/unreleased/sh-improve-container-tags-update-username.yml
new file mode 100644
index 00000000000..1a21ae84314
--- /dev/null
+++ b/changelogs/unreleased/sh-improve-container-tags-update-username.yml
@@ -0,0 +1,5 @@
+---
+title: Improve logging when username update fails due to registry tags
+merge_request: 22038
+author:
+type: other
diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb
index 3649990670b..22dc81acfda 100644
--- a/spec/models/namespace_spec.rb
+++ b/spec/models/namespace_spec.rb
@@ -82,6 +82,27 @@ describe Namespace do
it { expect(namespace.human_name).to eq(namespace.owner_name) }
end
+ describe '#first_project_with_container_registry_tags' do
+ let(:container_repository) { create(:container_repository) }
+ let!(:project) { create(:project, namespace: namespace, container_repositories: [container_repository]) }
+
+ before do
+ stub_container_registry_config(enabled: true)
+ end
+
+ it 'returns the project' do
+ stub_container_registry_tags(repository: :any, tags: ['tag'])
+
+ expect(namespace.first_project_with_container_registry_tags).to eq(project)
+ end
+
+ it 'returns no project' do
+ stub_container_registry_tags(repository: :any, tags: nil)
+
+ expect(namespace.first_project_with_container_registry_tags).to be_nil
+ end
+ end
+
describe '.search' do
let(:namespace) { create(:namespace) }
@@ -184,7 +205,8 @@ describe Namespace do
end
it 'raises an error about not movable project' do
- expect { namespace.move_dir }.to raise_error(/Namespace cannot be moved/)
+ expect { namespace.move_dir }.to raise_error(Gitlab::UpdatePathError,
+ /Namespace .* cannot be moved/)
end
end
end