2019-12-21 20:55:43 +05:30
|
|
|
# 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
|
2021-01-29 00:20:46 +05:30
|
|
|
include DiffHelper
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
expose :diff_files do |diffs, options|
|
|
|
|
submodule_links = Gitlab::SubmoduleLinks.new(merge_request.project.repository)
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
DiffFileEntity.represent(
|
2021-02-22 17:27:13 +05:30
|
|
|
diffs.diff_files(sorted: true),
|
2021-01-29 00:20:46 +05:30
|
|
|
options.merge(
|
|
|
|
submodule_links: submodule_links,
|
|
|
|
code_navigation_path: code_navigation_path(diffs),
|
2023-03-17 16:20:25 +05:30
|
|
|
conflicts: conflicts(allow_tree_conflicts: true)
|
2021-01-29 00:20:46 +05:30
|
|
|
)
|
|
|
|
)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
expose :pagination do
|
2021-09-30 23:02:18 +05:30
|
|
|
expose :total_pages do |diffs, options|
|
|
|
|
options.dig(:pagination_data, :total_pages)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def merge_request
|
|
|
|
options[:merge_request]
|
|
|
|
end
|
|
|
|
end
|