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

compare_test_reports_service.rb « ci « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2293f95f56b96b7b1fbba6484bbaf845e60f5328 (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
# frozen_string_literal: true

module Ci
  class CompareTestReportsService < ::BaseService
    def execute(base_pipeline, head_pipeline)
      # rubocop: disable CodeReuse/Serializer
      comparer = Gitlab::Ci::Reports::TestReportsComparer
        .new(base_pipeline&.test_reports, head_pipeline.test_reports)

      {
        status: :parsed,
        key: key(base_pipeline, head_pipeline),
        data: TestReportsComparerSerializer
          .new(project: project)
          .represent(comparer).as_json
      }
    rescue => e
      {
        status: :error,
        key: key(base_pipeline, head_pipeline),
        status_reason: e.message
      }
      # rubocop: enable CodeReuse/Serializer
    end

    def latest?(base_pipeline, head_pipeline, data)
      data&.fetch(:key, nil) == key(base_pipeline, head_pipeline)
    end

    private

    def key(base_pipeline, head_pipeline)
      [
        base_pipeline&.id, base_pipeline&.updated_at,
        head_pipeline&.id, head_pipeline&.updated_at
      ]
    end
  end
end