Commit 66eaa050 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'mo-code-coverage-project-resolver' into 'master'

Add code coverage summary resolver

See merge request gitlab-org/gitlab!46549
parents 2f7c87a8 67dfc0a0
......@@ -2779,7 +2779,7 @@ type CodeCoverageSummary {
"""
Latest date when the code coverage was created for the project.
"""
lastUpdatedAt: Time
lastUpdatedOn: Date
}
type Commit {
......
......@@ -7580,14 +7580,14 @@
"deprecationReason": null
},
{
"name": "lastUpdatedAt",
"name": "lastUpdatedOn",
"description": "Latest date when the code coverage was created for the project.",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Time",
"name": "Date",
"ofType": null
},
"isDeprecated": false,
......@@ -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. |
| `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
......
......@@ -146,23 +146,9 @@ module EE
::Types::Ci::CodeCoverageSummaryType,
null: true,
description: 'Code coverages summary associated with the project',
resolver: ::Resolvers::Ci::CodeCoverageSummaryResolver,
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)
::Security::CiConfiguration::SastParserService.new(project).configuration
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
field :coverage_count, GraphQL::INT_TYPE, null: true,
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.'
end
end
......
......@@ -30,7 +30,7 @@ module EE
result[project_id] = {
average_coverage: average_coverage,
coverage_count: coverage_count,
last_updated_at: date
last_updated_on: date
}
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
it { expect(described_class.graphql_name).to eq('CodeCoverageSummary') }
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) }
end
......
......@@ -36,12 +36,12 @@ RSpec.describe Ci::DailyBuildGroupReportResult do
project.id => {
average_coverage: 71.5,
coverage_count: 2,
last_updated_at: recent_build_group_report_result.date
last_updated_on: recent_build_group_report_result.date
},
project_2.id => {
average_coverage: 78.0,
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
codeCoverageSummary {
averageCoverage
coverageCount
lastUpdatedAt
lastUpdatedOn
}
}
QUERY
......@@ -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('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
......
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