2019-08-09 17:01:55 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class MergeRequestPollCachedWidgetEntity < IssuableEntity
|
2021-10-06 20:09:20 -04:00
|
|
|
include MergeRequestMetricsHelper
|
|
|
|
|
2019-08-09 17:01:55 -04:00
|
|
|
expose :auto_merge_enabled
|
|
|
|
expose :state
|
2020-09-10 08:08:54 -04:00
|
|
|
expose :merged_commit_sha
|
|
|
|
expose :short_merged_commit_sha
|
2019-08-09 17:01:55 -04:00
|
|
|
expose :merge_error
|
2020-04-15 14:09:36 -04:00
|
|
|
expose :public_merge_status, as: :merge_status
|
2019-08-09 17:01:55 -04:00
|
|
|
expose :merge_user_id
|
|
|
|
expose :source_branch
|
|
|
|
expose :source_project_id
|
|
|
|
expose :target_branch
|
|
|
|
expose :target_branch_sha
|
|
|
|
expose :target_project_id
|
|
|
|
expose :squash
|
|
|
|
expose :rebase_in_progress?, as: :rebase_in_progress
|
2020-09-28 05:09:35 -04:00
|
|
|
expose :default_squash_commit_message
|
2019-08-09 17:01:55 -04:00
|
|
|
expose :commits_count
|
|
|
|
expose :merge_ongoing?, as: :merge_ongoing
|
|
|
|
expose :work_in_progress?, as: :work_in_progress
|
|
|
|
expose :cannot_be_merged?, as: :has_conflicts
|
|
|
|
expose :can_be_merged?, as: :can_be_merged
|
|
|
|
expose :remove_source_branch?, as: :remove_source_branch
|
|
|
|
expose :source_branch_exists?, as: :source_branch_exists
|
|
|
|
expose :branch_missing?, as: :branch_missing
|
|
|
|
|
2020-09-28 05:09:35 -04:00
|
|
|
expose :commits_without_merge_commits, using: MergeRequestWidgetCommitEntity do |merge_request|
|
2019-11-20 07:06:01 -05:00
|
|
|
merge_request.recent_commits.without_merge_commits
|
2019-08-09 17:01:55 -04:00
|
|
|
end
|
2020-09-28 05:09:35 -04:00
|
|
|
|
2019-08-09 17:01:55 -04:00
|
|
|
expose :diff_head_sha do |merge_request|
|
|
|
|
merge_request.diff_head_sha.presence
|
|
|
|
end
|
|
|
|
expose :metrics do |merge_request|
|
|
|
|
metrics = build_metrics(merge_request)
|
|
|
|
|
|
|
|
MergeRequestMetricsEntity.new(metrics).as_json
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :diverged_commits_count do |merge_request|
|
|
|
|
if merge_request.open? && merge_request.diverged_from_target_branch?
|
|
|
|
merge_request.diverged_commits_count
|
|
|
|
else
|
|
|
|
0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-31 11:10:27 -04:00
|
|
|
expose :actual_head_pipeline, as: :pipeline, if: -> (mr, _) { presenter(mr).can_read_pipeline? } do |merge_request, options|
|
2020-09-28 17:10:29 -04:00
|
|
|
MergeRequests::PipelineEntity.represent(merge_request.actual_head_pipeline, options)
|
|
|
|
end
|
|
|
|
|
2021-07-27 05:10:08 -04:00
|
|
|
expose :merge_pipeline, if: ->(mr, _) { mr.merged? && can?(request.current_user, :read_pipeline, mr.target_project) } do |merge_request, options|
|
2021-04-01 08:08:56 -04:00
|
|
|
MergeRequests::PipelineEntity.represent(merge_request.merge_pipeline, options)
|
|
|
|
end
|
|
|
|
|
2019-08-09 17:01:55 -04:00
|
|
|
# Paths
|
|
|
|
#
|
|
|
|
expose :target_branch_commits_path do |merge_request|
|
|
|
|
presenter(merge_request).target_branch_commits_path
|
|
|
|
end
|
|
|
|
|
2021-04-07 05:09:06 -04:00
|
|
|
expose :merge_request_widget_path do |merge_request|
|
|
|
|
widget_project_json_merge_request_path(merge_request.target_project, merge_request, format: :json)
|
|
|
|
end
|
|
|
|
|
2019-08-09 17:01:55 -04:00
|
|
|
expose :target_branch_tree_path do |merge_request|
|
|
|
|
presenter(merge_request).target_branch_tree_path
|
|
|
|
end
|
|
|
|
|
2020-09-10 08:08:54 -04:00
|
|
|
expose :merged_commit_path do |merge_request|
|
|
|
|
if sha = merge_request.merged_commit_sha
|
|
|
|
project_commit_path(merge_request.project, sha)
|
2019-08-09 17:01:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :source_branch_path do |merge_request|
|
|
|
|
presenter(merge_request).source_branch_path
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :source_branch_with_namespace_link do |merge_request|
|
|
|
|
presenter(merge_request).source_branch_with_namespace_link
|
|
|
|
end
|
|
|
|
|
2019-12-06 07:06:21 -05:00
|
|
|
expose :diffs_path do |merge_request|
|
|
|
|
diffs_project_merge_request_path(merge_request.project, merge_request)
|
|
|
|
end
|
|
|
|
|
2020-06-30 14:09:13 -04:00
|
|
|
expose :squash_enabled_by_default do |merge_request|
|
|
|
|
presenter(merge_request).project.squash_enabled_by_default?
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :squash_readonly do |merge_request|
|
|
|
|
presenter(merge_request).project.squash_readonly?
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :squash_on_merge do |merge_request|
|
|
|
|
presenter(merge_request).squash_on_merge?
|
|
|
|
end
|
|
|
|
|
2020-07-15 14:09:09 -04:00
|
|
|
expose :api_approvals_path do |merge_request|
|
|
|
|
presenter(merge_request).api_approvals_path
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :api_approve_path do |merge_request|
|
|
|
|
presenter(merge_request).api_approve_path
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :api_unapprove_path do |merge_request|
|
|
|
|
presenter(merge_request).api_unapprove_path
|
|
|
|
end
|
|
|
|
|
2021-04-07 20:09:11 -04:00
|
|
|
expose :test_reports_path do |merge_request|
|
|
|
|
if merge_request.has_test_reports?
|
|
|
|
test_reports_project_merge_request_path(merge_request.project, merge_request, format: :json)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :accessibility_report_path do |merge_request|
|
|
|
|
if merge_request.has_accessibility_reports?
|
|
|
|
accessibility_reports_project_merge_request_path(merge_request.project, merge_request, format: :json)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :codequality_reports_path do |merge_request|
|
|
|
|
if merge_request.has_codequality_reports?
|
|
|
|
codequality_reports_project_merge_request_path(merge_request.project, merge_request, format: :json)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :terraform_reports_path do |merge_request|
|
|
|
|
if merge_request.has_terraform_reports?
|
|
|
|
terraform_reports_project_merge_request_path(merge_request.project, merge_request, format: :json)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :exposed_artifacts_path do |merge_request|
|
|
|
|
if merge_request.has_exposed_artifacts?
|
|
|
|
exposed_artifacts_project_merge_request_path(merge_request.project, merge_request, format: :json)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-05 07:10:36 -05:00
|
|
|
expose :blob_path do
|
|
|
|
expose :head_path, if: -> (mr, _) { mr.source_branch_sha } do |merge_request|
|
|
|
|
project_blob_path(merge_request.project, merge_request.source_branch_sha)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :base_path, if: -> (mr, _) { mr.diff_base_sha } do |merge_request|
|
|
|
|
project_blob_path(merge_request.project, merge_request.diff_base_sha)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-09 17:01:55 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
delegate :current_user, to: :request
|
|
|
|
|
|
|
|
def presenter(merge_request)
|
|
|
|
@presenters ||= {}
|
|
|
|
@presenters[merge_request] ||= MergeRequestPresenter.new(merge_request, current_user: current_user) # rubocop: disable CodeReuse/Presenter
|
|
|
|
end
|
|
|
|
end
|
2019-11-18 22:06:07 -05:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
MergeRequestPollCachedWidgetEntity.prepend_mod_with('MergeRequestPollCachedWidgetEntity')
|