diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-21 03:14:37 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-21 03:14:37 +0300 |
commit | b605abacd983a19c30dc364e8014fc758f496e98 (patch) | |
tree | 783eac05129bad193709909307d09ab2960793e7 /app/services/projects | |
parent | 235f755398a6a199b22e4924e7a81670b0dfdaef (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/projects')
-rw-r--r-- | app/services/projects/after_rename_service.rb | 30 | ||||
-rw-r--r-- | app/services/projects/update_service.rb | 27 |
2 files changed, 45 insertions, 12 deletions
diff --git a/app/services/projects/after_rename_service.rb b/app/services/projects/after_rename_service.rb index 93d68eec3bc..e173655ed05 100644 --- a/app/services/projects/after_rename_service.rb +++ b/app/services/projects/after_rename_service.rb @@ -38,7 +38,7 @@ module Projects end def execute - first_ensure_no_registry_tags_are_present + rename_base_repository_in_registry! expire_caches_before_rename rename_or_migrate_repository! send_move_instructions @@ -49,11 +49,25 @@ module Projects publish_event end - def first_ensure_no_registry_tags_are_present + def rename_base_repository_in_registry! return unless project.has_container_registry_tags? - raise RenameFailedError, "Project #{full_path_before} cannot be renamed because images are " \ - "present in its container registry" + ensure_registry_tags_can_be_handled + + result = ContainerRegistry::GitlabApiClient.rename_base_repository_path( + full_path_before, name: project_path) + + return if result == :ok + + rename_failed!("Renaming the base repository in the registry failed with error #{result}.") + end + + def ensure_registry_tags_can_be_handled + return if Feature.enabled?(:renaming_project_with_tags, project) && + ContainerRegistry::GitlabApiClient.supports_gitlab_api? + + rename_failed!("Project #{full_path_before} cannot be renamed because images are " \ + "present in its container registry") end def expire_caches_before_rename @@ -66,7 +80,9 @@ module Projects .new(project, full_path_before) .execute - rename_failed! unless success + return if success + + rename_failed!("Repository #{full_path_before} could not be renamed to #{full_path_after}") end def send_move_instructions @@ -117,9 +133,7 @@ module Projects project.namespace.full_path end - def rename_failed! - error = "Repository #{full_path_before} could not be renamed to #{full_path_after}" - + def rename_failed!(error) log_error(error) raise RenameFailedError, error diff --git a/app/services/projects/update_service.rb b/app/services/projects/update_service.rb index 336e887c241..cfcbe42997b 100644 --- a/app/services/projects/update_service.rb +++ b/app/services/projects/update_service.rb @@ -61,11 +61,8 @@ module Projects raise_validation_error(s_('UpdateProject|New visibility level not allowed!')) end - if renaming_project_with_container_registry_tags? - raise_validation_error(s_('UpdateProject|Cannot rename project because it contains container registry tags!')) - end - validate_default_branch_change + validate_renaming_project_with_tags end def validate_default_branch_change @@ -92,6 +89,28 @@ module Projects end end + def validate_renaming_project_with_tags + return unless renaming_project_with_container_registry_tags? + + unless Feature.enabled?(:renaming_project_with_tags, project) && + ContainerRegistry::GitlabApiClient.supports_gitlab_api? + raise ValidationError, s_('UpdateProject|Cannot rename project because it contains container registry tags!') + end + + dry_run = ContainerRegistry::GitlabApiClient.rename_base_repository_path( + project.full_path, name: params[:path], dry_run: true) + + return if dry_run == :accepted + + log_error("Dry run failed for renaming project with tags: #{project.full_path}, error: #{dry_run}") + raise_validation_error( + format( + s_("UpdateProject|Cannot rename project, the container registry path rename validation failed: %{error}"), + error: dry_run.to_s.titleize + ) + ) + end + def ambiguous_head_documentation_link url = Rails.application.routes.url_helpers.help_page_path('user/project/repository/branches/index', anchor: 'error-ambiguous-head-branch-exists') |