Support fetching versioned README for CI Catalog resource in GraphQl
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
namefilter argument toVersionsResolver. - Updates
VersionsFinderso that it can filter by version name. - Adds the
readme_htmlfield toVersionType.
Resolves #429279 (closed).
How to set up and validate locally
- Create a published catalog resource. You can seed one quickly by running the following command in your
gitlabdirectory:
bundle exec rake "gitlab:seed:ci_catalog_resources[<YOUR-GROUP-PATH>, 1, true]"
-
In your catalog resource project, update the
README.mdcontent with## Version 1and commit the change tobranch1. Then update theREADME.mdcontent with## Version 2and commit the change tobranch2. -
Create tags for the branches, named
tag1andtag2respectively. Then create a release for each tag. The release fortag2should have a later date thantag1. -
Go to
http://gdk.test:3000/-/graphql-explorerand 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.
- 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" }
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.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #429279 (closed)

