2018-11-05 08:45:36 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Ci
|
2019-10-21 11:05:58 -04:00
|
|
|
# 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
|
2018-11-05 08:45:36 -05:00
|
|
|
class CompareReportsBaseService < ::BaseService
|
|
|
|
def execute(base_pipeline, head_pipeline)
|
|
|
|
comparer = comparer_class.new(get_report(base_pipeline), get_report(head_pipeline))
|
|
|
|
{
|
|
|
|
status: :parsed,
|
|
|
|
key: key(base_pipeline, head_pipeline),
|
|
|
|
data: serializer_class
|
2019-07-02 13:40:21 -04:00
|
|
|
.new(**serializer_params)
|
2018-11-05 08:45:36 -05:00
|
|
|
.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
|
|
|
|
|
|
|
|
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-07-02 13:40:21 -04:00
|
|
|
def serializer_params
|
2019-09-11 11:33:50 -04:00
|
|
|
{ project: project, current_user: current_user }
|
2019-07-02 13:40:21 -04:00
|
|
|
end
|
|
|
|
|
2018-11-05 08:45:36 -05:00
|
|
|
def get_report(pipeline)
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|