2018-07-19 14:43:13 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
class DiffsEntity < Grape::Entity
|
|
|
|
include DiffHelper
|
|
|
|
include RequestAwareEntity
|
|
|
|
|
|
|
|
expose :real_size
|
|
|
|
expose :size
|
|
|
|
|
|
|
|
expose :branch_name do |diffs|
|
|
|
|
merge_request&.source_branch
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :target_branch_name do |diffs|
|
|
|
|
merge_request&.target_branch
|
|
|
|
end
|
|
|
|
|
2018-09-26 04:28:50 -04:00
|
|
|
expose :commit do |diffs, options|
|
|
|
|
CommitEntity.represent options[:commit], options.merge(
|
|
|
|
type: :full,
|
2018-10-03 05:08:00 -04:00
|
|
|
commit_url_params: { merge_request_iid: merge_request&.iid },
|
|
|
|
pipeline_ref: merge_request&.source_branch,
|
|
|
|
pipeline_project: merge_request&.source_project
|
2018-09-26 04:28:50 -04:00
|
|
|
)
|
2018-06-21 08:22:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :merge_request_diff, using: MergeRequestDiffEntity do |diffs|
|
|
|
|
options[:merge_request_diff]
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :start_version, using: MergeRequestDiffEntity do |diffs|
|
|
|
|
options[:start_version]
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :latest_diff do |diffs|
|
|
|
|
options[:latest_diff]
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :latest_version_path, if: -> (*) { merge_request } do |diffs|
|
|
|
|
diffs_project_merge_request_path(merge_request&.project, merge_request)
|
|
|
|
end
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-06-21 08:22:40 -04:00
|
|
|
expose :added_lines do |diffs|
|
|
|
|
diffs.diff_files.sum(&:added_lines)
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-06-21 08:22:40 -04:00
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-06-21 08:22:40 -04:00
|
|
|
expose :removed_lines do |diffs|
|
|
|
|
diffs.diff_files.sum(&:removed_lines)
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
expose :render_overflow_warning do |diffs|
|
|
|
|
render_overflow_warning?(diffs.diff_files)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :email_patch_path, if: -> (*) { merge_request } do |diffs|
|
|
|
|
merge_request_path(merge_request, format: :patch)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :plain_diff_path, if: -> (*) { merge_request } do |diffs|
|
|
|
|
merge_request_path(merge_request, format: :diff)
|
|
|
|
end
|
|
|
|
|
2019-07-17 09:06:19 -04:00
|
|
|
expose :diff_files do |diffs, options|
|
|
|
|
submodule_links = Gitlab::SubmoduleLinks.new(merge_request.project.repository)
|
|
|
|
DiffFileEntity.represent(diffs.diff_files, options.merge(submodule_links: submodule_links))
|
|
|
|
end
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
expose :merge_request_diffs, using: MergeRequestDiffEntity, if: -> (_, options) { options[:merge_request_diffs]&.any? } do |diffs|
|
|
|
|
options[:merge_request_diffs]
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request
|
|
|
|
options[:merge_request]
|
|
|
|
end
|
|
|
|
end
|