Skip to content

Make Catalog resource ID become the fullpath of a resource

What does this MR do and why?

We want to change the CI resources URLs to not use an actual numbered ID, but the full path of the ci resource, so from explore/catalog/1 to explore/catalog/gitlab-org/sast. To do so, we can leverage rails routes config param: :fullpath to accept IDs that aren't numbers.

To do so, the graphql query to get resources should support getting either the numbered ID or the fullpath of a resource.

Then when a user lands on /gitlab-org/sast, the client will execute the following graphql query:

query getCiCatalogResourceDetails($fullPath # This should be the `gitlab-org/sast` value`) {
  ciCatalogResource(fullPath: $fullPath) {
    ...allDetailsFields 

From the API side, we need to support the the listing.rb of the catalog to accept a full_path argument to find a resource this way. ID should still be supported for now and we can remove it later if we want to.

Then in the rails config, we are updating 2 major thing:

  1. Generate the new routes with the *full_path argument. Anything after catalog/ is combined as the fullpath
  2. Helpers methods still accept a catalog resource directly because we overwrite the to_param method of the Ci::Catalog::Resource model to return the full_path.

Screenshots or screen recordings

Before After
Screenshot_2023-11-29_at_10.02.44_AM Screenshot_2023-11-29_at_9.59.16_AM

How to set up and validate locally

  1. Enable the FF global_ci_catalog
  2. Create a few projects that you will be able to convert to Ci resources. Create them under the admin namespace for ease of testing.
  3. Once you have done so, get the ID of the first new project you wanted to convert. Then in Rails console, run:
projects = Project.where("id > ?", your_first_project_id -1)
projects.each do |project|
  project.update!(description: 'description') 
  ::Ci::Catalog::Resource.new(project_id: project.id).save   
end  
  1. Then to publish the resource:
Ci::Catalog::Resource.last.publish!
  1. Navigate to Explore -> CI/CD Catalog
  2. Notice that you see Catalog resources
  3. Click on any resource
  4. Notice that the URL is explore/catalog/group-path/project-path
  5. Notice that all data loads (this test the client-side routing)
  6. Refresh the page
  7. Notice the data still loads (this test the rails side)

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 #428949 (closed)

Edited by Frédéric Caplette

Merge request reports