Commit 95f30e26 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'eb-mr-widget-builds-coverages' into 'master'

Return builds with coverage in MR widget JSON

See merge request gitlab-org/gitlab!40533
parents ce721bd7 4ac22588
......@@ -867,6 +867,10 @@ module Ci
builds.latest.with_reports(reports_scope)
end
def builds_with_coverage
builds.with_coverage
end
def has_reports?(reports_scope)
complete? && latest_report_builds(reports_scope).exists?
end
......
......@@ -295,7 +295,7 @@ class MergeRequest < ApplicationRecord
alias_attribute :auto_merge_enabled, :merge_when_pipeline_succeeds
alias_method :issuing_parent, :target_project
delegate :active?, to: :head_pipeline, prefix: true, allow_nil: true
delegate :active?, :builds_with_coverage, to: :head_pipeline, prefix: true, allow_nil: true
delegate :success?, :active?, to: :actual_head_pipeline, prefix: true, allow_nil: true
RebaseLockTimeout = Class.new(StandardError)
......
# frozen_string_literal: true
class BuildCoverageEntity < Grape::Entity
expose :name, :coverage
end
......@@ -73,6 +73,8 @@ class MergeRequestPollWidgetEntity < Grape::Entity
presenter(merge_request).pipeline_coverage_delta
end
expose :head_pipeline_builds_with_coverage, as: :builds_with_coverage, using: BuildCoverageEntity
expose :cancel_auto_merge_path do |merge_request|
presenter(merge_request).cancel_auto_merge_path
end
......
---
title: Return builds with coverage in MR widget JSON response
merge_request: 40533
author:
type: added
......@@ -49,6 +49,7 @@ RSpec.describe Projects::MergeRequests::ContentController do
do_request(:widget)
expect(response).to match_response_schema('entities/merge_request_poll_widget')
expect(response.headers['Poll-Interval']).to eq('10000')
end
......@@ -64,6 +65,20 @@ RSpec.describe Projects::MergeRequests::ContentController do
expect(response.headers['Poll-Interval']).to eq('300000')
end
end
context 'with coverage data' do
let(:merge_request) { create(:merge_request, target_project: project, source_project: project, head_pipeline: head_pipeline) }
let!(:base_pipeline) { create(:ci_empty_pipeline, project: project, ref: merge_request.target_branch, sha: merge_request.diff_base_sha) }
let!(:head_pipeline) { create(:ci_empty_pipeline, project: project) }
let!(:rspec_base) { create(:ci_build, name: 'rspec', coverage: 93.1, pipeline: base_pipeline) }
let!(:rspec_head) { create(:ci_build, name: 'rspec', coverage: 97.1, pipeline: head_pipeline) }
it 'renders widget MR entity as json' do
do_request(:widget)
expect(response).to match_response_schema('entities/merge_request_poll_widget')
end
end
end
end
......
......@@ -22,6 +22,14 @@
"only_allow_merge_if_pipeline_succeeds": { "type": "boolean" },
"has_ci": { "type": "boolean" },
"ci_status": { "type": ["string", "null"] },
"pipeline_coverage_delta": { "type": ["float", "null"] },
"builds_with_coverage": {
"type": ["array", "null"],
"items": {
"type": "object",
"required": ["name", "coverage"]
}
},
"cancel_auto_merge_path": { "type": ["string", "null"] },
"test_reports_path": { "type": ["string", "null"] },
"create_issue_to_resolve_discussions_path": { "type": ["string", "null"] },
......
......@@ -3441,4 +3441,17 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
it { is_expected.to eq(Gitlab::Git::TAG_REF_PREFIX + pipeline.source_ref.to_s) }
end
end
describe "#builds_with_coverage" do
it 'returns builds with coverage only' do
rspec = create(:ci_build, name: 'rspec', coverage: 97.1, pipeline: pipeline)
jest = create(:ci_build, name: 'jest', coverage: 94.1, pipeline: pipeline)
karma = create(:ci_build, name: 'karma', coverage: nil, pipeline: pipeline)
builds = pipeline.builds_with_coverage
expect(builds).to include(rspec, jest)
expect(builds).not_to include(karma)
end
end
end
......@@ -4112,4 +4112,14 @@ RSpec.describe MergeRequest, factory_default: :keep do
expect(context[:label_url_method]).to eq(:project_merge_requests_url)
end
end
describe '#head_pipeline_builds_with_coverage' do
it 'delegates to head_pipeline' do
expect(subject)
.to delegate_method(:builds_with_coverage)
.to(:head_pipeline)
.with_prefix
.with_arguments(allow_nil: true)
end
end
end
......@@ -285,4 +285,20 @@ RSpec.describe MergeRequestPollWidgetEntity do
end
end
end
describe '#builds_with_coverage' do
it 'serializes the builds with coverage' do
allow(resource).to receive(:head_pipeline_builds_with_coverage).and_return([
double(name: 'rspec', coverage: 91.5),
double(name: 'jest', coverage: 94.1)
])
result = subject[:builds_with_coverage]
expect(result).to eq([
{ name: 'rspec', coverage: 91.5 },
{ name: 'jest', coverage: 94.1 }
])
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