2016-11-18 21:19:04 -05:00
|
|
|
class MergeRequestEntity < IssuableEntity
|
2017-05-09 00:15:34 -04:00
|
|
|
include RequestAwareEntity
|
|
|
|
|
2016-11-18 21:19:04 -05:00
|
|
|
expose :in_progress_merge_commit_sha
|
|
|
|
expose :merge_commit_sha
|
|
|
|
expose :merge_error
|
|
|
|
expose :merge_params
|
|
|
|
expose :merge_status
|
|
|
|
expose :merge_user_id
|
2017-02-17 08:56:13 -05:00
|
|
|
expose :merge_when_pipeline_succeeds
|
2016-11-18 21:19:04 -05:00
|
|
|
expose :source_branch
|
|
|
|
expose :source_project_id
|
|
|
|
expose :target_branch
|
|
|
|
expose :target_project_id
|
2017-05-09 00:15:34 -04:00
|
|
|
|
|
|
|
# Events
|
|
|
|
expose :merge_event, using: EventEntity
|
|
|
|
expose :closed_event, using: EventEntity
|
|
|
|
|
|
|
|
# User entities
|
|
|
|
expose :author, using: UserEntity
|
|
|
|
expose :merge_user, using: UserEntity
|
|
|
|
|
|
|
|
# Diff sha's
|
|
|
|
expose :diff_head_sha do |merge_request|
|
|
|
|
merge_request.diff_head_sha if merge_request.diff_head_commit
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :merge_commit_sha
|
|
|
|
expose :merge_commit_message
|
2017-05-29 03:58:20 -04:00
|
|
|
expose :head_pipeline, with: PipelineDetailsEntity, as: :pipeline
|
2017-05-09 00:15:34 -04:00
|
|
|
|
|
|
|
# Booleans
|
2017-07-31 18:01:36 -04:00
|
|
|
expose :merge_ongoing?, as: :merge_ongoing
|
2017-05-09 00:15:34 -04:00
|
|
|
expose :work_in_progress?, as: :work_in_progress
|
|
|
|
expose :source_branch_exists?, as: :source_branch_exists
|
|
|
|
expose :mergeable_discussions_state?, as: :mergeable_discussions_state
|
|
|
|
expose :branch_missing?, as: :branch_missing
|
|
|
|
expose :commits_count
|
|
|
|
expose :cannot_be_merged?, as: :has_conflicts
|
|
|
|
expose :can_be_merged?, as: :can_be_merged
|
2017-05-24 20:54:57 -04:00
|
|
|
expose :remove_source_branch?, as: :remove_source_branch
|
2017-05-09 00:15:34 -04:00
|
|
|
|
|
|
|
expose :project_archived do |merge_request|
|
|
|
|
merge_request.project.archived?
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :only_allow_merge_if_pipeline_succeeds do |merge_request|
|
|
|
|
merge_request.project.only_allow_merge_if_pipeline_succeeds?
|
|
|
|
end
|
|
|
|
|
|
|
|
# CI related
|
|
|
|
expose :has_ci?, as: :has_ci
|
|
|
|
expose :ci_status do |merge_request|
|
|
|
|
presenter(merge_request).ci_status
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :issues_links do
|
|
|
|
expose :assign_to_closing do |merge_request|
|
|
|
|
presenter(merge_request).assign_to_closing_issues_link
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :closing do |merge_request|
|
|
|
|
presenter(merge_request).closing_issues_links
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :mentioned_but_not_closing do |merge_request|
|
|
|
|
presenter(merge_request).mentioned_issues_links
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :source_branch_with_namespace_link do |merge_request|
|
|
|
|
presenter(merge_request).source_branch_with_namespace_link
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :source_branch_path do |merge_request|
|
|
|
|
presenter(merge_request).source_branch_path
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :current_user do
|
|
|
|
expose :can_remove_source_branch do |merge_request|
|
|
|
|
merge_request.source_branch_exists? && merge_request.can_remove_source_branch?(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :can_revert_on_current_merge_request do |merge_request|
|
|
|
|
presenter(merge_request).can_revert_on_current_merge_request?
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :can_cherry_pick_on_current_merge_request do |merge_request|
|
|
|
|
presenter(merge_request).can_cherry_pick_on_current_merge_request?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Paths
|
|
|
|
#
|
2017-07-11 12:49:22 -04:00
|
|
|
expose :target_branch_commits_path do |merge_request|
|
|
|
|
presenter(merge_request).target_branch_commits_path
|
|
|
|
end
|
|
|
|
|
2017-07-11 10:48:59 -04:00
|
|
|
expose :target_branch_tree_path do |merge_request|
|
|
|
|
presenter(merge_request).target_branch_tree_path
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
|
|
|
|
2017-05-10 16:05:25 -04:00
|
|
|
expose :new_blob_path do |merge_request|
|
2017-05-10 19:29:00 -04:00
|
|
|
if can?(current_user, :push_code, merge_request.project)
|
2017-06-29 13:06:35 -04:00
|
|
|
project_new_blob_path(merge_request.project, merge_request.source_branch)
|
2017-05-10 19:29:00 -04:00
|
|
|
end
|
2017-05-10 16:05:25 -04:00
|
|
|
end
|
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
expose :conflict_resolution_path do |merge_request|
|
|
|
|
presenter(merge_request).conflict_resolution_path
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :remove_wip_path do |merge_request|
|
|
|
|
presenter(merge_request).remove_wip_path
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :cancel_merge_when_pipeline_succeeds_path do |merge_request|
|
|
|
|
presenter(merge_request).cancel_merge_when_pipeline_succeeds_path
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :create_issue_to_resolve_discussions_path do |merge_request|
|
|
|
|
presenter(merge_request).create_issue_to_resolve_discussions_path
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :merge_path do |merge_request|
|
|
|
|
presenter(merge_request).merge_path
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :cherry_pick_in_fork_path do |merge_request|
|
|
|
|
presenter(merge_request).cherry_pick_in_fork_path
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :revert_in_fork_path do |merge_request|
|
|
|
|
presenter(merge_request).revert_in_fork_path
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :email_patches_path do |merge_request|
|
2017-06-29 13:06:35 -04:00
|
|
|
project_merge_request_path(merge_request.project, merge_request, format: :patch)
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :plain_diff_path do |merge_request|
|
2017-06-29 13:06:35 -04:00
|
|
|
project_merge_request_path(merge_request.project, merge_request, format: :diff)
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :status_path do |merge_request|
|
2017-06-29 13:06:35 -04:00
|
|
|
project_merge_request_path(merge_request.target_project, merge_request, format: :json)
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :ci_environments_status_path do |merge_request|
|
2017-06-29 13:06:35 -04:00
|
|
|
ci_environments_status_project_merge_request_path(merge_request.project, merge_request)
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :merge_commit_message_with_description do |merge_request|
|
|
|
|
merge_request.merge_commit_message(include_description: true)
|
|
|
|
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
|
|
|
|
|
|
|
|
expose :commit_change_content_path do |merge_request|
|
2017-06-29 13:06:35 -04:00
|
|
|
commit_change_content_project_merge_request_path(merge_request.project, merge_request)
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
delegate :current_user, to: :request
|
|
|
|
|
|
|
|
def presenter(merge_request)
|
|
|
|
@presenters ||= {}
|
|
|
|
@presenters[merge_request] ||= MergeRequestPresenter.new(merge_request, current_user: current_user)
|
|
|
|
end
|
2016-11-18 21:19:04 -05:00
|
|
|
end
|