2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Ci
|
|
|
|
class CompareTestReportsService < ::BaseService
|
|
|
|
def execute(base_pipeline, head_pipeline)
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/Serializer
|
2018-11-18 11:00:15 +05:30
|
|
|
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
|
|
|
|
}
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/Serializer
|
2018-11-18 11:00:15 +05:30
|
|
|
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
|