Add coverage filter to pipelines resolver/finder
Original discussion thread for context: #343687 (comment 968458740)
Problem to solve
We have an MVC for the Project Quality Summary, but getting the latest data to display on it is limited by what we can filter by when we query for pipelines. For projects like `gitlab-org/gitlab' where some of the pipelines run for the default branch have test runs and coverage data and others don't, because we can only get the latest pipeline and not the latest pipeline with coverage data, the MVC is not as useful as it could be.
Proposal
We could add a filtering argument to the pipelines resolver/finder so that we can get the latest pipeline with test runs and coverage data.
Maybe something like this?:
diff --git a/app/finders/ci/pipelines_finder.rb b/app/finders/ci/pipelines_finder.rb
index 712d5f8c6fb..96bf6709f00 100644
--- a/app/finders/ci/pipelines_finder.rb
+++ b/app/finders/ci/pipelines_finder.rb
@@ -36,6 +36,7 @@ def execute
items = by_yaml_errors(items)
items = by_updated_at(items)
items = by_source(items)
+ items = by_coverage(items)
sort_items(items)
end
@@ -169,5 +170,11 @@ def sort_items(items)
items.order(order_by => sort)
end
# rubocop: enable CodeReuse/ActiveRecord
+
+ def by_coverage(items)
+ return items unless params[:with_coverage]
+
+ items #.where(some job in this pipeline has coverage)
+ end
end
end
diff --git a/app/graphql/resolvers/concerns/resolves_pipelines.rb b/app/graphql/resolvers/concerns/resolves_pipelines.rb
index 764ed9b15fd..35cea3b44db 100644
--- a/app/graphql/resolvers/concerns/resolves_pipelines.rb
+++ b/app/graphql/resolvers/concerns/resolves_pipelines.rb
@@ -36,6 +36,11 @@ module ResolvesPipelines
GraphQL::Types::String,
required: false,
description: "Filter pipelines by the user that triggered the pipeline."
+
+ argument :with_coverage,
+ GraphQL::Types::Boolean,
+ required: false,
+ description: "Filter only pipelines with coverage data."
end
class_methods do
Then we can run this query to get what we need:
{
project(fullPath: "gitlab-org/gitlab") {
id
pipelines(ref: "master", scope: FINISHED, withCoverage: true, first: 1) { // use the with_coverage argument
nodes {
id
status
path
coverage
testReportSummary {
total {
count
error
failed
skipped
success
suiteError
time
}
}
}
}
}
}