2019-10-10 08:06:19 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class DiffsMetadataEntity < DiffsEntity
|
|
|
|
unexpose :diff_files
|
2021-07-28 11:09:57 -04:00
|
|
|
expose :diff_files do |diffs, options|
|
|
|
|
DiffFileMetadataEntity.represent(
|
|
|
|
diffs.raw_diff_files(sorted: true),
|
|
|
|
options.merge(
|
|
|
|
conflicts: conflicts(allow_tree_conflicts: options[:allow_tree_conflicts])
|
|
|
|
)
|
|
|
|
)
|
2020-12-15 04:10:00 -05:00
|
|
|
end
|
2020-08-17 08:10:12 -04:00
|
|
|
|
|
|
|
expose :conflict_resolution_path do |_, options|
|
|
|
|
presenter(options[:merge_request]).conflict_resolution_path
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :has_conflicts do |_, options|
|
|
|
|
options[:merge_request].cannot_be_merged?
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :can_merge do |_, options|
|
|
|
|
options[:merge_request].can_be_merged_by?(request.current_user)
|
|
|
|
end
|
|
|
|
|
2021-01-14 13:10:59 -05:00
|
|
|
expose :project_path
|
|
|
|
expose :project_name
|
|
|
|
|
|
|
|
expose :username
|
|
|
|
expose :user_full_name
|
|
|
|
|
2020-08-17 08:10:12 -04:00
|
|
|
private
|
|
|
|
|
2021-01-14 13:10:59 -05:00
|
|
|
def project_path
|
|
|
|
request.project&.full_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_name
|
|
|
|
request.project&.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def username
|
|
|
|
request.current_user&.username
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_full_name
|
|
|
|
request.current_user&.name
|
|
|
|
end
|
|
|
|
|
2020-08-17 08:10:12 -04:00
|
|
|
def presenter(merge_request)
|
|
|
|
@presenters ||= {}
|
|
|
|
@presenters[merge_request] ||= MergeRequestPresenter.new(merge_request, current_user: request.current_user) # rubocop: disable CodeReuse/Presenter
|
|
|
|
end
|
2019-10-10 08:06:19 -04:00
|
|
|
end
|