2018-07-19 14:43:13 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
class MergeRequestDiffEntity < Grape::Entity
|
|
|
|
include Gitlab::Routing
|
|
|
|
include GitHelper
|
|
|
|
include MergeRequestsHelper
|
|
|
|
|
|
|
|
expose :version_index do |merge_request_diff|
|
|
|
|
@merge_request_diffs = options[:merge_request_diffs]
|
|
|
|
diff = options[:merge_request_diff]
|
|
|
|
|
|
|
|
next unless diff.present?
|
|
|
|
next unless @merge_request_diffs.size > 1
|
|
|
|
|
|
|
|
version_index(merge_request_diff)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :created_at
|
|
|
|
expose :commits_count
|
|
|
|
|
|
|
|
expose :latest?, as: :latest
|
|
|
|
|
|
|
|
expose :short_commit_sha do |merge_request_diff|
|
2019-10-24 11:06:02 -04:00
|
|
|
next unless merge_request_diff.head_commit_sha
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
short_sha(merge_request_diff.head_commit_sha)
|
|
|
|
end
|
|
|
|
|
2019-01-16 08:18:10 -05:00
|
|
|
expose :base_version_path do |merge_request_diff|
|
|
|
|
project = merge_request.target_project
|
|
|
|
|
|
|
|
next unless project
|
|
|
|
|
|
|
|
merge_request_version_path(project, merge_request, merge_request_diff)
|
|
|
|
end
|
|
|
|
|
2020-02-13 19:09:07 -05:00
|
|
|
expose :head_version_path do |merge_request_diff|
|
|
|
|
project = merge_request.target_project
|
|
|
|
|
|
|
|
next unless project && merge_request.diffable_merge_ref?
|
|
|
|
|
|
|
|
diffs_project_merge_request_path(project, merge_request, diff_head: true)
|
|
|
|
end
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expose :version_path do |merge_request_diff|
|
|
|
|
start_sha = options[:start_sha]
|
|
|
|
project = merge_request.target_project
|
|
|
|
|
|
|
|
next unless project
|
|
|
|
|
|
|
|
merge_request_version_path(project, merge_request, merge_request_diff, start_sha)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :compare_path do |merge_request_diff|
|
|
|
|
project = merge_request.target_project
|
|
|
|
diff = options[:merge_request_diff]
|
|
|
|
|
|
|
|
if project && diff
|
|
|
|
merge_request_version_path(project, merge_request, diff, merge_request_diff.head_commit_sha)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request
|
|
|
|
options[:merge_request]
|
|
|
|
end
|
|
|
|
end
|