Welcome to mirror list, hosted at ThFree Co, Russian Federation.

coverage_report_service.rb « pipeline_artifacts « ci « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b0acb1d5a0b98b65c328b0e7ac493c83a05455a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true
module Ci
  module PipelineArtifacts
    class CoverageReportService
      include Gitlab::Utils::StrongMemoize

      def initialize(pipeline)
        @pipeline = pipeline
      end

      def execute
        return if pipeline.has_coverage_reports?
        return if report.empty?

        pipeline.pipeline_artifacts.create!(
          project_id: pipeline.project_id,
          file_type: :code_coverage,
          file_format: Ci::PipelineArtifact::REPORT_TYPES.fetch(:code_coverage),
          size: carrierwave_file["tempfile"].size,
          file: carrierwave_file,
          expire_at: Ci::PipelineArtifact::EXPIRATION_DATE.from_now
        )
      end

      private

      attr_reader :pipeline

      def report
        strong_memoize(:report) do
          Gitlab::Ci::Reports::CoverageReportGenerator.new(pipeline).report
        end
      end

      def carrierwave_file
        strong_memoize(:carrier_wave_file) do
          CarrierWaveStringFile.new_file(
            file_content: report.to_json,
            filename: Ci::PipelineArtifact::DEFAULT_FILE_NAMES.fetch(:code_coverage),
            content_type: 'application/json'
          )
        end
      end
    end
  end
end