Commit 50020977 authored by Vladimir Shushlin's avatar Vladimir Shushlin

Add Ci::Pipeline#latest_report_builds method

parent 76e12073
......@@ -800,13 +800,17 @@ module Ci
@latest_builds_with_artifacts ||= builds.latest.with_artifacts_not_expired.to_a
end
def latest_report_builds(reports_scope = ::Ci::JobArtifact.with_reports)
builds.latest.with_reports(reports_scope)
end
def has_reports?(reports_scope)
complete? && builds.latest.with_reports(reports_scope).exists?
complete? && latest_report_builds(reports_scope).exists?
end
def test_reports
Gitlab::Ci::Reports::TestReports.new.tap do |test_reports|
builds.latest.with_reports(Ci::JobArtifact.test_reports).preload(:project).find_each do |build|
latest_report_builds(Ci::JobArtifact.test_reports).preload(:project).find_each do |build|
build.collect_test_reports!(test_reports)
end
end
......@@ -828,7 +832,7 @@ module Ci
def coverage_reports
Gitlab::Ci::Reports::CoverageReports.new.tap do |coverage_reports|
builds.latest.with_reports(Ci::JobArtifact.coverage_reports).each do |build|
latest_report_builds(Ci::JobArtifact.coverage_reports).each do |build|
build.collect_coverage_reports!(coverage_reports)
end
end
......@@ -836,7 +840,7 @@ module Ci
def terraform_reports
::Gitlab::Ci::Reports::TerraformReports.new.tap do |terraform_reports|
builds.latest.with_reports(::Ci::JobArtifact.terraform_reports).each do |build|
latest_report_builds(::Ci::JobArtifact.terraform_reports).each do |build|
build.collect_terraform_reports!(terraform_reports)
end
end
......
......@@ -2749,6 +2749,30 @@ describe Ci::Pipeline, :mailer do
end
end
describe '#latest_report_builds' do
it 'returns build with test artifacts' do
test_build = create(:ci_build, :test_reports, pipeline: pipeline, project: project)
coverage_build = create(:ci_build, :coverage_reports, pipeline: pipeline, project: project)
create(:ci_build, :artifacts, pipeline: pipeline, project: project)
expect(pipeline.latest_report_builds).to contain_exactly(test_build, coverage_build)
end
it 'filters builds by scope' do
test_build = create(:ci_build, :test_reports, pipeline: pipeline, project: project)
create(:ci_build, :coverage_reports, pipeline: pipeline, project: project)
expect(pipeline.latest_report_builds(Ci::JobArtifact.test_reports)).to contain_exactly(test_build)
end
it 'only returns not retried builds' do
test_build = create(:ci_build, :test_reports, pipeline: pipeline, project: project)
create(:ci_build, :test_reports, :retried, pipeline: pipeline, project: project)
expect(pipeline.latest_report_builds).to contain_exactly(test_build)
end
end
describe '#has_reports?' do
subject { pipeline.has_reports?(Ci::JobArtifact.test_reports) }
......
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