diff options
Diffstat (limited to 'app/models/ci/build.rb')
-rw-r--r-- | app/models/ci/build.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 93bbee49c09..bf931a04592 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -69,6 +69,11 @@ module Ci where('NOT EXISTS (?)', Ci::JobArtifact.select(1).where('ci_builds.id = ci_job_artifacts.job_id').trace) end + scope :with_test_reports, ->() do + includes(:job_artifacts_junit) # Prevent N+1 problem when iterating each ci_job_artifact row + .where('EXISTS (?)', Ci::JobArtifact.select(1).where('ci_builds.id = ci_job_artifacts.job_id').test_reports) + end + scope :with_artifacts_stored_locally, -> { with_artifacts_archive.where(artifacts_file_store: [nil, LegacyArtifactUploader::Store::LOCAL]) } scope :with_artifacts_not_expired, ->() { with_artifacts_archive.where('artifacts_expire_at IS NULL OR artifacts_expire_at > ?', Time.now) } scope :with_expired_artifacts, ->() { with_artifacts_archive.where('artifacts_expire_at < ?', Time.now) } @@ -627,8 +632,31 @@ module Ci running? && runner_session_url.present? end + def collect_test_reports!(test_reports) + raise ArgumentError, 'build does not have test reports' unless has_test_reports? + + test_reports.get_suite(group_name).tap do |test_suite| + each_test_report do |file_type, blob| + parse_test_report!(test_suite, file_type, blob) + end + end + end + private + def each_test_report + Ci::JobArtifact::TEST_REPORT_FILE_TYPES.each do |file_type| + public_send("job_artifacts_#{file_type}").each_blob do |blob| # rubocop:disable GitlabSecurity/PublicSend + yield file_type, blob + end + end + end + + def parse_test_report!(test_suite, file_type, blob) + "Gitlab::Ci::Parsers::#{file_type.capitalize}Parser".constantize + .new(blob).parse!(test_suite) + end + def update_artifacts_size self.artifacts_size = legacy_artifacts_file&.size end |