Commit b27630ba authored by Sean McGivern's avatar Sean McGivern

Merge branch 'mo-fix-coverage-summary-data-all-projects' into 'master'

Allow group projects to be queried by code coverage with GraphQL

See merge request gitlab-org/gitlab!55182
parents 2c3ae4c3 69aec783
...@@ -6,15 +6,21 @@ module EE ...@@ -6,15 +6,21 @@ module EE
extend ActiveSupport::Concern extend ActiveSupport::Concern
prepended do prepended do
argument :has_code_coverage, GraphQL::BOOLEAN_TYPE,
required: false,
default_value: false,
description: 'Returns only the projects which have code coverage.'
argument :has_vulnerabilities, GraphQL::BOOLEAN_TYPE, argument :has_vulnerabilities, GraphQL::BOOLEAN_TYPE,
required: false, required: false,
default_value: false, default_value: false,
description: 'Returns only the projects which have vulnerabilities.' description: 'Returns only the projects which have vulnerabilities.'
end end
def resolve(include_subgroups:, search:, sort:, has_vulnerabilities: false) def resolve(include_subgroups:, search:, sort:, has_vulnerabilities: false, has_code_coverage: false)
projects = super(include_subgroups: include_subgroups, search: search, sort: sort) projects = super(include_subgroups: include_subgroups, search: search, sort: sort)
projects = projects.has_vulnerabilities if has_vulnerabilities projects = projects.has_vulnerabilities if has_vulnerabilities
projects = projects.with_code_coverage if has_code_coverage
projects = projects.order_by_total_repository_size_excess_desc(namespace.actual_size_limit) if sort == :storage projects = projects.order_by_total_repository_size_excess_desc(namespace.actual_size_limit) if sort == :storage
projects projects
end end
......
...@@ -130,6 +130,10 @@ module EE ...@@ -130,6 +130,10 @@ module EE
.limit(limit) .limit(limit)
end end
scope :with_code_coverage, -> do
joins(:daily_build_group_report_results).merge(::Ci::DailyBuildGroupReportResult.with_coverage.with_default_branch).group(:id)
end
scope :including_project, ->(project) { where(id: project) } scope :including_project, ->(project) { where(id: project) }
scope :with_wiki_enabled, -> { with_feature_enabled(:wiki) } scope :with_wiki_enabled, -> { with_feature_enabled(:wiki) }
scope :within_shards, -> (shard_names) { where(repository_storage: Array(shard_names)) } scope :within_shards, -> (shard_names) { where(repository_storage: Array(shard_names)) }
......
---
title: Query group projects by code coverage with GraphQL
merge_request: 55182
author:
type: added
...@@ -57,15 +57,34 @@ RSpec.describe Resolvers::NamespaceProjectsResolver do ...@@ -57,15 +57,34 @@ RSpec.describe Resolvers::NamespaceProjectsResolver do
it { is_expected.to eq([project_1, project_2, project_3]) } it { is_expected.to eq([project_1, project_2, project_3]) }
end end
end end
context 'has_code_coverage' do
subject(:projects) { resolve_projects(has_code_coverage: has_code_coverage) }
let!(:coverage_1) { create(:ci_daily_build_group_report_result, project: project_1) }
context 'when has_code_coverage is false' do
let(:has_code_coverage) { false }
it { is_expected.to contain_exactly(project_1, project_2) }
end
context 'when has_code_coverage is true' do
let(:has_code_coverage) { true }
it { is_expected.to contain_exactly(project_1) }
end
end
end end
end end
def resolve_projects(has_vulnerabilities: false, sort: :similarity) def resolve_projects(has_vulnerabilities: false, sort: :similarity, has_code_coverage: false)
args = { args = {
include_subgroups: false, include_subgroups: false,
has_vulnerabilities: has_vulnerabilities, has_vulnerabilities: has_vulnerabilities,
sort: sort, sort: sort,
search: nil search: nil,
has_code_coverage: has_code_coverage
} }
resolve(described_class, obj: group, args: args, ctx: { current_user: current_user }) resolve(described_class, obj: group, args: args, ctx: { current_user: current_user })
......
...@@ -363,6 +363,19 @@ RSpec.describe Project do ...@@ -363,6 +363,19 @@ RSpec.describe Project do
it { is_expected.to eq([project_2, project_3, project_1]) } it { is_expected.to eq([project_2, project_3, project_1]) }
end end
describe '.with_code_coverage' do
let_it_be(:project_1) { create(:project) }
let_it_be(:project_2) { create(:project) }
let_it_be(:project_3) { create(:project) }
let!(:coverage_1) { create(:ci_daily_build_group_report_result, project: project_1) }
let!(:coverage_2) { create(:ci_daily_build_group_report_result, project: project_2) }
subject { described_class.with_code_coverage }
it { is_expected.to contain_exactly(project_1, project_2) }
end
end end
describe 'validations' do describe 'validations' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment