Skip to content

Allow renaming paths of projects with registry tags

Adie (she/her) requested to merge 424801-rename-project-with-tags into master

What does this MR do and why?

In this MR, we use the new rename repository API exposed by the Container Registry to facilitate renaming projects (changing the project path) from Gitlab Rails.

Currently, we raise an error when the user attempts to change the project path of a project with existing container registry tags. With this new rename repository API endpoint, we can now allow the renaming of such projects and we use the new endpoint to update the project's resources in the container registry.

Screenshot_2023-10-29_at_14.08.39

In Allow GitlabApiClient to call the new rename en... (#423995 - closed), we have exposed this new endpoint via the GitlabAPIClient and in this MR, we will be using it.

From GitLab Rails Plan for "Allowing renaming projec... (#420755 - closed), we can also see that the new API endpoint exposes a dry-run function and we use this to validate that we can continue with the rename operation.

This new feature is available only when the Gitlab API is supported and also behind a feature flag renaming_project_with_tags.

Screenshots or screen recordings

  1. When the feature flag is not enabled or the Gitlab API is not supported, we show an error when trying to change the path of a project with tags. (existing message)

Screenshot_2023-10-29_at_15.34.01

  1. When the feature flag is enabled and the Gitlab API is supported, and the rename was successful, we show a success message (existing message)

Screenshot_2023-10-29_at_15.28.56

  1. When the feature flag is enabled and the Gitlab API is supported, but the dry-run / validation for the rename failed, then we show an error (new message). Prior to running the actual rename, we first run the rename with a dry_run: true and if this fails, we return an error with the following message:

Screenshot_2023-10-29_at_15.41.44

How to set up and validate locally

Note: To run this, the metadata database should be setup and redis should be connected as well.

Metadata database: local development setup guide

And for Redis (you can have a different setup, this runs redis on port 6380),

redis-server --port 6380

Once you have set these up, the Gitlab API should now be accessible and you can try the following command in the console:

ContainerRegistry::GitlabApiClient.supports_gitlab_api?
# => true

Current Behaviour (Renaming a project with tags fails)

  1. Choose or create a test project and ensure that there are tags.

Screenshot_2023-10-29_at_16.12.17

  1. Head over to the Settings of the project, and choose General.

  2. Head over to the Advanced section at the bottom and expand it.

Screenshot_2023-10-29_at_16.16.37

  1. When you scroll through the setting under the Advanced section, you will see the following form. Try changing the path and click the Change path button.

Screenshot_2023-10-29_at_16.17.11

  1. You will receive an error as we're trying to rename a project with tags.

Screenshot_2023-10-29_at_15.34.01

New Behaviour (Renaming a project with tags is allowed)

  1. In rails console enable the feature flag fully
    Feature.enable(:renaming_project_with_tags)
  2. We can reuse the project with tags that we had above and try to rename it. You can check the project in the container registry database as well:
psql -U postgres
\c registry_dev
select * from repositories;

id | ... |  name  |         path         |
 2 | ... | proj-a | october-group/proj-a |
  1. Head to Settings > General > Advanced and scroll to the Change Path option:

Screenshot_2023-10-29_at_16.17.11

  1. Change the path and click the Change Path button.

Screenshot_2023-10-29_at_16.53.12

  1. The changing of the path should succeed and the changes reflected in the database.

Screenshot_2023-10-29_at_16.52.48

select * from repositories;

id | ... |  name  |         path         |
 2 | ... | proj-1 | october-group/proj-1 |

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #424801 (closed)

Edited by Adie (she/her)

Merge request reports