Skip to content

Support fetching versioned README for CI Catalog resource in GraphQl

Leaminn Ma requested to merge add-ci-catalog-resource-version-readme into master

What does this MR do and why?

Background context:

A Catalog Resource is a project that can have multiple Versions. A Version is equivalent to the project's Release. The Version's name identifier is equivalent to the Release's tag. So given a Version's name, we should be able to retrieve the README blob from the corresponding commit.

This MR:

This MR adds fields to GraphQl so that we can fetch the versioned README content from the ciCatalogResource(s) endpoints. Specifically, it:

  • Adds the name filter argument to VersionsResolver.
  • Updates VersionsFinder so that it can filter by version name.
  • Adds the readme_html field to VersionType.

Resolves #429279 (closed).

How to set up and validate locally

  1. Create a published catalog resource. You can seed one quickly by running the following command in your gitlab directory:
bundle exec rake "gitlab:seed:ci_catalog_resources[<YOUR-GROUP-PATH>, 1, true]"
  1. In your catalog resource project, update the README.md content with ## Version 1 and commit the change to branch1. Then update the README.md content with ## Version 2 and commit the change to branch2.

  2. Create tags for the branches, named tag1 and tag2 respectively. Then create a release for each tag. The release for tag2 should have a later date than tag1.

  3. Go to http://gdk.test:3000/-/graphql-explorer and test the following query. Update the path variable as needed.

query getCiCatalogResourceReadme($fullPath: ID!, $version: String) {
  ciCatalogResource(fullPath: $fullPath) {
    id
    name
    versions(name: $version) {
      nodes {
        id
        name
        releasedAt
        readmeHtml
      }
    }
  }
}
{ "fullPath": "group-a/ci_seed_resource_0", "version": "tag1" }

Observe that the README content returned corresponds to the given version name.

Screenshot_2024-01-03_at_3.20.37_PM

  1. Test the following query and confirm that the README content outputted is of the latest version (i.e. "Version 2").
query getCiCatalogResourceReadme($fullPath: ID!) {
  ciCatalogResource(fullPath: $fullPath) {
    id
    name
    latestVersion {
      id
      name
      releasedAt
      readmeHtml
    }
  }
}
{ "fullPath": "group-a/ci_seed_resource_0" }

Screenshot_2024-01-03_at_3.23.39_PM

Query plan

We may improve this query in the future by removing the need to JOIN with releases in #436410 (closed).

SELECT "catalog_resource_versions".*
FROM "catalog_resource_versions"
INNER JOIN "releases" ON "releases"."id" = "catalog_resource_versions"."release_id"
WHERE "catalog_resource_versions"."catalog_resource_id" = 1
AND "releases"."tag" = 'tag1'

Query plan link: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/25057/commands/79592

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

Edited by Leaminn Ma

Merge request reports

Loading