2019-10-09 17:06:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Serializes diffs with pagination data.
|
|
|
|
#
|
|
|
|
# Avoid adding more keys to this serializer as processing the
|
|
|
|
# diff file serialization is not cheap.
|
|
|
|
#
|
|
|
|
class PaginatedDiffEntity < Grape::Entity
|
|
|
|
include RequestAwareEntity
|
2020-11-13 13:09:11 -05:00
|
|
|
include DiffHelper
|
2019-10-09 17:06:24 -04:00
|
|
|
|
|
|
|
expose :diff_files do |diffs, options|
|
|
|
|
submodule_links = Gitlab::SubmoduleLinks.new(merge_request.project.repository)
|
2020-04-02 05:08:14 -04:00
|
|
|
|
2020-10-27 11:08:39 -04:00
|
|
|
DiffFileEntity.represent(
|
2020-12-15 04:10:00 -05:00
|
|
|
diffs.diff_files(sorted: true),
|
2020-10-27 11:08:39 -04:00
|
|
|
options.merge(
|
|
|
|
submodule_links: submodule_links,
|
2020-11-13 13:09:11 -05:00
|
|
|
code_navigation_path: code_navigation_path(diffs),
|
2021-07-21 17:10:10 -04:00
|
|
|
conflicts: conflicts(allow_tree_conflicts: options[:allow_tree_conflicts])
|
2020-10-27 11:08:39 -04:00
|
|
|
)
|
|
|
|
)
|
2019-10-09 17:06:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :pagination do
|
2021-06-28 02:07:45 -04:00
|
|
|
expose :total_pages do |diffs, options|
|
|
|
|
options.dig(:pagination_data, :total_pages)
|
2019-10-09 17:06:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def merge_request
|
|
|
|
options[:merge_request]
|
|
|
|
end
|
|
|
|
end
|