Draft: Add pipeline status to GraphQL projects query
What does this MR do and why?
Related to #482803
In &13066 we are moving Your work
-> Projects
to Vue and using GraphQL as the data source. We need to be able to get the pipeline status for projects from the GraphQL query but this is not possible at the moment. This MR adds a lastest_pipeline_detailed_status
field that returns detailed pipeline status for the latest pipeline.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Database
Raw SQL
Click to expand
From ::Ci::Pipeline.latest_pipeline_per_commit_and_project
SELECT DISTINCT ON (sha, project_id)
*
FROM
"ci_pipelines"
WHERE ("ci_pipelines"."project_id" = 7
AND "ci_pipelines"."sha" = 'c36b5a7137a25b64c35b1d5f8bfd8a7e60581bfb'
OR "ci_pipelines"."project_id" = 2
AND "ci_pipelines"."sha" = 'ddd0f15ae83993f5cb66a927a28673882e99100b'
OR "ci_pipelines"."project_id" = 8
AND "ci_pipelines"."sha" = '588440f66559714280628a4f9799f0c4eb880a4a'
OR "ci_pipelines"."project_id" = 6
AND "ci_pipelines"."sha" = 'd2e7e613a597bec6b16c946e42c91950dcc1a215')
ORDER BY
"ci_pipelines"."sha" ASC,
"ci_pipelines"."project_id" ASC,
"ci_pipelines"."id" DESC
From pipeline&.number_of_warnings
SELECT
COUNT(*) AS "count_all",
"p_ci_builds"."commit_id" AS "p_ci_builds_commit_id"
FROM
"p_ci_builds"
WHERE
"p_ci_builds"."commit_id" IN (566, 9, 5)
AND ("p_ci_builds"."retried" = FALSE
OR "p_ci_builds"."retried" IS NULL)
AND "p_ci_builds"."allow_failure" = TRUE
AND "p_ci_builds"."status" IN ('failed', 'canceled')
GROUP BY
"p_ci_builds"."commit_id"
Needed for Ability.allowed?(current_user, :read_pipeline, pipeline)
SELECT
"namespaces"."id",
"namespaces"."name",
"namespaces"."path",
"namespaces"."owner_id",
"namespaces"."created_at",
"namespaces"."updated_at",
"namespaces"."type",
"namespaces"."description",
"namespaces"."avatar",
"namespaces"."membership_lock",
"namespaces"."share_with_group_lock",
"namespaces"."visibility_level",
"namespaces"."request_access_enabled",
"namespaces"."ldap_sync_status",
"namespaces"."ldap_sync_error",
"namespaces"."ldap_sync_last_update_at",
"namespaces"."ldap_sync_last_successful_update_at",
"namespaces"."ldap_sync_last_sync_at",
"namespaces"."description_html",
"namespaces"."lfs_enabled",
"namespaces"."parent_id",
"namespaces"."shared_runners_minutes_limit",
"namespaces"."repository_size_limit",
"namespaces"."require_two_factor_authentication",
"namespaces"."two_factor_grace_period",
"namespaces"."cached_markdown_version",
"namespaces"."project_creation_level",
"namespaces"."runners_token",
"namespaces"."file_template_project_id",
"namespaces"."saml_discovery_token",
"namespaces"."runners_token_encrypted",
"namespaces"."custom_project_templates_group_id",
"namespaces"."auto_devops_enabled",
"namespaces"."extra_shared_runners_minutes_limit",
"namespaces"."last_ci_minutes_notification_at",
"namespaces"."last_ci_minutes_usage_notification_level",
"namespaces"."subgroup_creation_level",
"namespaces"."max_pages_size",
"namespaces"."max_artifacts_size",
"namespaces"."mentions_disabled",
"namespaces"."default_branch_protection",
"namespaces"."max_personal_access_token_lifetime",
"namespaces"."push_rule_id",
"namespaces"."shared_runners_enabled",
"namespaces"."allow_descendants_override_disabled_shared_runners",
"namespaces"."traversal_ids",
"namespaces"."organization_id"
FROM
"namespaces"
WHERE
"namespaces"."type" = 'Group'
AND "namespaces"."id" IN (24, 35, 33)
SELECT
"project_features".*
FROM
"project_features"
WHERE
"project_features"."project_id" IN (2, 8, 7)
How to set up and validate locally
- Open rails console (
bin/rails console
) - Clear pipeline cache
projects = Project.all
projects.each { |project| Gitlab::Cache::Ci::ProjectPipelineStatus.new(project).delete_from_cache }
- Go to http://gdk.test:3000/-/graphql-explorer
- Open the dev tools and go to
Network
tab - Run this query (make sure you have a project with a pipeline)
query getProjects {
projects(membership: true) {
nodes {
nameWithNamespace
lastestPipelineDetailedStatus {
name
label
}
}
}
}
- Copy the
x-request-id
header - Go to http://gdk.test:3000/
- In the upper right corner of performance bar, click the
+
symbol and pasted the request ID - Choose request from dropdown
- Run the query again without clearing pipeline cache to see cached result
Edited by Peter Hegman