Commit 67dfc0a0 authored by Maxime Orefice's avatar Maxime Orefice Committed by Mayra Cabrera

Add code coverage summary resolver

This commit moves our code coverage summary resolver to its own
resolver class. It also changes the type of our lastUpdatedAt field
to a date field.
parent ce8c53db
...@@ -2779,7 +2779,7 @@ type CodeCoverageSummary { ...@@ -2779,7 +2779,7 @@ type CodeCoverageSummary {
""" """
Latest date when the code coverage was created for the project. Latest date when the code coverage was created for the project.
""" """
lastUpdatedAt: Time lastUpdatedOn: Date
} }
type Commit { type Commit {
......
...@@ -7580,14 +7580,14 @@ ...@@ -7580,14 +7580,14 @@
"deprecationReason": null "deprecationReason": null
}, },
{ {
"name": "lastUpdatedAt", "name": "lastUpdatedOn",
"description": "Latest date when the code coverage was created for the project.", "description": "Latest date when the code coverage was created for the project.",
"args": [ "args": [
], ],
"type": { "type": {
"kind": "SCALAR", "kind": "SCALAR",
"name": "Time", "name": "Date",
"ofType": null "ofType": null
}, },
"isDeprecated": false, "isDeprecated": false,
...@@ -437,7 +437,7 @@ Represents the code coverage summary for a project. ...@@ -437,7 +437,7 @@ Represents the code coverage summary for a project.
| ----- | ---- | ----------- | | ----- | ---- | ----------- |
| `averageCoverage` | Float | Average percentage of the different code coverage results available for the project. | | `averageCoverage` | Float | Average percentage of the different code coverage results available for the project. |
| `coverageCount` | Int | Number of different code coverage results available. | | `coverageCount` | Int | Number of different code coverage results available. |
| `lastUpdatedAt` | Time | Latest date when the code coverage was created for the project. | | `lastUpdatedOn` | Date | Latest date when the code coverage was created for the project. |
### Commit ### Commit
......
...@@ -146,23 +146,9 @@ module EE ...@@ -146,23 +146,9 @@ module EE
::Types::Ci::CodeCoverageSummaryType, ::Types::Ci::CodeCoverageSummaryType,
null: true, null: true,
description: 'Code coverages summary associated with the project', description: 'Code coverages summary associated with the project',
resolver: ::Resolvers::Ci::CodeCoverageSummaryResolver,
feature_flag: :group_coverage_data_report feature_flag: :group_coverage_data_report
def code_coverage_summary
BatchLoader::GraphQL.for(project.id).batch do |project_ids, loader|
results = ::Ci::DailyBuildGroupReportResult
.by_projects(project_ids)
.with_coverage
.with_default_branch
.latest
.summaries_per_project
results.each do |project_id, summary|
loader.call(project_id, summary)
end
end
end
def self.sast_ci_configuration(project) def self.sast_ci_configuration(project)
::Security::CiConfiguration::SastParserService.new(project).configuration ::Security::CiConfiguration::SastParserService.new(project).configuration
end end
......
# frozen_string_literal: true
module Resolvers
module Ci
class CodeCoverageSummaryResolver < BaseResolver
type ::Types::Ci::CodeCoverageSummaryType, null: true
alias_method :project, :object
def resolve(**args)
BatchLoader::GraphQL.for(project.id).batch do |project_ids, loader|
results = ::Ci::DailyBuildGroupReportResult
.by_projects(project_ids)
.with_coverage
.with_default_branch
.latest
.summaries_per_project
results.each do |project_id, summary|
loader.call(project_id, summary)
end
end
end
end
end
end
...@@ -13,7 +13,7 @@ module Types ...@@ -13,7 +13,7 @@ module Types
field :coverage_count, GraphQL::INT_TYPE, null: true, field :coverage_count, GraphQL::INT_TYPE, null: true,
description: 'Number of different code coverage results available.' description: 'Number of different code coverage results available.'
field :last_updated_at, Types::TimeType, null: true, field :last_updated_on, Types::DateType, null: true,
description: 'Latest date when the code coverage was created for the project.' description: 'Latest date when the code coverage was created for the project.'
end end
end end
......
...@@ -30,7 +30,7 @@ module EE ...@@ -30,7 +30,7 @@ module EE
result[project_id] = { result[project_id] = {
average_coverage: average_coverage, average_coverage: average_coverage,
coverage_count: coverage_count, coverage_count: coverage_count,
last_updated_at: date last_updated_on: date
} }
end end
end end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Resolvers::Ci::CodeCoverageSummaryResolver do
include GraphqlHelpers
describe '#resolve' do
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
context 'when project has coverage' do
let!(:coverage_1) { create(:ci_daily_build_group_report_result, project: project) }
let!(:coverage_2) { create(:ci_daily_build_group_report_result, project: project, group_name: 'karma') }
let(:expected_results) do
{
average_coverage: 77.0,
coverage_count: 2,
last_updated_on: Date.current
}
end
it 'returns coverage summary for the project as a batch' do
results = batch_sync do
resolve_coverages
end
expect(results).to eq(expected_results)
end
end
context 'when project does not have coverage' do
it 'returns nil' do
results = batch_sync do
resolve_coverages
end
expect(results).to be_nil
end
end
end
def resolve_coverages(args = {}, context = { current_user: current_user })
resolve(described_class, obj: project, args: args, ctx: context)
end
end
...@@ -6,7 +6,7 @@ RSpec.describe GitlabSchema.types['CodeCoverageSummary'] do ...@@ -6,7 +6,7 @@ RSpec.describe GitlabSchema.types['CodeCoverageSummary'] do
it { expect(described_class.graphql_name).to eq('CodeCoverageSummary') } it { expect(described_class.graphql_name).to eq('CodeCoverageSummary') }
describe 'fields' do describe 'fields' do
let(:fields) { %i[average_coverage coverage_count last_updated_at] } let(:fields) { %i[average_coverage coverage_count last_updated_on] }
it { expect(described_class).to have_graphql_fields(fields) } it { expect(described_class).to have_graphql_fields(fields) }
end end
......
...@@ -36,12 +36,12 @@ RSpec.describe Ci::DailyBuildGroupReportResult do ...@@ -36,12 +36,12 @@ RSpec.describe Ci::DailyBuildGroupReportResult do
project.id => { project.id => {
average_coverage: 71.5, average_coverage: 71.5,
coverage_count: 2, coverage_count: 2,
last_updated_at: recent_build_group_report_result.date last_updated_on: recent_build_group_report_result.date
}, },
project_2.id => { project_2.id => {
average_coverage: 78.0, average_coverage: 78.0,
coverage_count: 1, coverage_count: 1,
last_updated_at: build_group_report_result_2.date last_updated_on: build_group_report_result_2.date
} }
} }
......
...@@ -16,7 +16,7 @@ RSpec.describe 'Getting code coverage summary in a project' do ...@@ -16,7 +16,7 @@ RSpec.describe 'Getting code coverage summary in a project' do
codeCoverageSummary { codeCoverageSummary {
averageCoverage averageCoverage
coverageCount coverageCount
lastUpdatedAt lastUpdatedOn
} }
} }
QUERY QUERY
...@@ -45,7 +45,7 @@ RSpec.describe 'Getting code coverage summary in a project' do ...@@ -45,7 +45,7 @@ RSpec.describe 'Getting code coverage summary in a project' do
expect(code_coverage_summary_graphql_data.dig('averageCoverage')).to eq(77.0) expect(code_coverage_summary_graphql_data.dig('averageCoverage')).to eq(77.0)
expect(code_coverage_summary_graphql_data.dig('coverageCount')).to eq(1) expect(code_coverage_summary_graphql_data.dig('coverageCount')).to eq(1)
expect(code_coverage_summary_graphql_data.dig('lastUpdatedAt')).to eq(daily_build_group_report_result.date.to_s) expect(code_coverage_summary_graphql_data.dig('lastUpdatedOn')).to eq(daily_build_group_report_result.date.to_s)
end end
end end
......
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