Skip to content
Snippets Groups Projects

Allow transfer of project with registry tags

Merged Adie (she/her) requested to merge 499163-allow-transferring-proj-with-tags into master
3 files
+ 115
11
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -92,10 +92,7 @@ def transfer(project)
raise TransferError, s_("TransferProject|Project with same name or path in target namespace already exists")
end
if project.has_container_registry_tags?
# We currently don't support renaming repository if it contains tags in container registry
raise TransferError, s_('TransferProject|Project cannot be transferred, because tags are present in its container registry')
end
verify_if_project_with_tags_can_be_transferred(project) if project.has_container_registry_tags?
if !new_namespace_has_same_root?(project) && project.has_namespaced_npm_packages?
raise TransferError, s_("TransferProject|Root namespace can't be updated if the project has NPM packages scoped to the current root level namespace.")
@@ -105,6 +102,22 @@ def transfer(project)
end
# rubocop: enable CodeReuse/ActiveRecord
def verify_if_project_with_tags_can_be_transferred(project)
unless Feature.enabled?(:transfer_project_with_tags, project) &&
ContainerRegistry::GitlabApiClient.supports_gitlab_api?
raise TransferError, s_('TransferProject|Project cannot be transferred, because tags are present in its container registry')
end
unless new_namespace_has_same_root?(project)
raise TransferError, s_('TransferProject|Project cannot be transferred to a different top-level namespace, because tags are present in its container registry')
end
dry_run = update_project_namespace_in_registry(project.full_path, new_namespace.full_path, dry_run: true)
return if dry_run == :accepted
raise TransferError, format(s_('TransferProject|Project cannot be transferred, the container registry path rename validation failed: %{error}'), error: dry_run.to_s.titleize)
end
def new_namespace_has_same_root?(project)
new_namespace.root_ancestor == project.namespace.root_ancestor
end
@@ -129,6 +142,11 @@ def proceed_to_transfer
# Move uploads
move_project_uploads(project)
# Update Container Registry
if project.has_container_registry_tags?
update_project_namespace_in_registry(@old_path, @new_namespace.full_path, dry_run: false)
end
update_integrations
project.old_path_with_namespace = @old_path
@@ -152,6 +170,14 @@ def proceed_to_transfer
refresh_permissions
end
def update_project_namespace_in_registry(old_project_path, new_namespace_path, dry_run:)
ContainerRegistry::GitlabApiClient.move_repository_to_namespace(
old_project_path,
namespace: new_namespace_path,
dry_run: dry_run
)
end
# Overridden in EE
def post_update_hooks(project, _old_group)
ensure_personal_project_owner_membership(project)
Loading