Allow renaming paths of projects with registry tags
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.
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
- 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)
- When the feature flag is enabled and the Gitlab API is supported, and the rename was successful, we show a success message (existing message)
- 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:
How to set up and validate locally
Note: To run this, the metadata database should be setup and redis should be connected as well.
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)
- Choose or create a test project and ensure that there are tags.
-
Head over to the Settings of the project, and choose General.
-
Head over to the Advanced section at the bottom and expand it.
- 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.
- You will receive an error as we're trying to rename a project with tags.
New Behaviour (Renaming a project with tags is allowed)
- In rails console enable the feature flag fully
Feature.enable(:renaming_project_with_tags)
- 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 |
- Head to Settings > General > Advanced and scroll to the Change Path option:
- Change the path and click the Change Path button.
- The changing of the path should succeed and the changes reflected in the database.
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.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #424801 (closed)