debian-mirror-gitlab/app/services/ci/compare_reports_base_service.rb

66 lines
1.7 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
module Ci
2019-12-26 22:10:19 +05:30
# TODO: when using this class with exposed artifacts we see that there are
# 2 responsibilities:
# 1. reactive caching interface (same in all cases)
# 2. data generator (report comparison in most of the case but not always)
# issue: https://gitlab.com/gitlab-org/gitlab/issues/34224
2019-02-15 15:39:39 +05:30
class CompareReportsBaseService < ::BaseService
def execute(base_pipeline, head_pipeline)
2021-01-29 00:20:46 +05:30
base_report = get_report(base_pipeline)
head_report = get_report(head_pipeline)
comparer = build_comparer(base_report, head_report)
2020-04-22 19:07:51 +05:30
2019-02-15 15:39:39 +05:30
{
status: :parsed,
key: key(base_pipeline, head_pipeline),
data: serializer_class
2019-09-30 21:07:59 +05:30
.new(**serializer_params)
2019-02-15 15:39:39 +05:30
.represent(comparer).as_json
}
rescue Gitlab::Ci::Parsers::ParserError => e
{
status: :error,
key: key(base_pipeline, head_pipeline),
status_reason: e.message
}
end
def latest?(base_pipeline, head_pipeline, data)
data&.fetch(:key, nil) == key(base_pipeline, head_pipeline)
end
2020-04-22 19:07:51 +05:30
protected
2021-01-29 00:20:46 +05:30
def build_comparer(base_report, head_report)
comparer_class.new(base_report, head_report)
2020-04-22 19:07:51 +05:30
end
2019-02-15 15:39:39 +05:30
private
def key(base_pipeline, head_pipeline)
[
base_pipeline&.id, base_pipeline&.updated_at,
head_pipeline&.id, head_pipeline&.updated_at
]
end
def comparer_class
raise NotImplementedError
end
def serializer_class
raise NotImplementedError
end
2019-09-30 21:07:59 +05:30
def serializer_params
2019-12-04 20:38:33 +05:30
{ project: project, current_user: current_user }
2019-09-30 21:07:59 +05:30
end
2019-02-15 15:39:39 +05:30
def get_report(pipeline)
raise NotImplementedError
end
end
end