2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
class MergeRequestWidgetEntity < Grape::Entity
|
|
|
|
include RequestAwareEntity
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
expose :id
|
|
|
|
expose :iid
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
expose :source_project_full_path do |merge_request|
|
|
|
|
merge_request.source_project&.full_path
|
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
expose :target_project_full_path do |merge_request|
|
|
|
|
merge_request.project&.full_path
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expose :email_patches_path do |merge_request|
|
|
|
|
project_merge_request_path(merge_request.project, merge_request, format: :patch)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expose :plain_diff_path do |merge_request|
|
|
|
|
project_merge_request_path(merge_request.project, merge_request, format: :diff)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expose :merge_request_basic_path do |merge_request|
|
|
|
|
project_merge_request_path(merge_request.target_project, merge_request, serializer: :basic, format: :json)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expose :merge_request_widget_path do |merge_request|
|
|
|
|
widget_project_json_merge_request_path(merge_request.target_project, merge_request, format: :json)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expose :merge_request_cached_widget_path do |merge_request|
|
|
|
|
cached_widget_project_json_merge_request_path(merge_request.target_project, merge_request, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expose :commit_change_content_path do |merge_request|
|
|
|
|
commit_change_content_project_merge_request_path(merge_request.project, merge_request)
|
2019-03-02 22:35:43 +05:30
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expose :conflicts_docs_path do |merge_request|
|
|
|
|
help_page_path('user/project/merge_requests/resolve_conflicts.md')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expose :merge_request_pipelines_docs_path do |merge_request|
|
|
|
|
help_page_path('ci/merge_request_pipelines/index.md')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expose :ci_environments_status_path do |merge_request|
|
|
|
|
ci_environments_status_project_merge_request_path(merge_request.project, merge_request)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expose :merge_request_add_ci_config_path, if: ->(mr, _) { can_add_ci_config_path?(mr) } do |merge_request|
|
|
|
|
project_new_blob_path(
|
|
|
|
merge_request.source_project,
|
|
|
|
merge_request.source_branch,
|
|
|
|
file_name: '.gitlab-ci.yml',
|
|
|
|
commit_message: s_("CommitMessage|Add %{file_name}") % { file_name: Gitlab::FileDetector::PATTERNS[:gitlab_ci] }
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :human_access do |merge_request|
|
|
|
|
merge_request.project.team.human_max_access(current_user&.id)
|
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
# Rendering and redacting Markdown can be expensive. These links are
|
|
|
|
# just nice to have in the merge request widget, so only
|
|
|
|
# include them if they are explicitly requested on first load.
|
|
|
|
expose :issues_links, if: -> (_, opts) { opts[:issues_links] } do
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
delegate :current_user, to: :request
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def presenter(merge_request)
|
|
|
|
@presenters ||= {}
|
2019-12-04 20:38:33 +05:30
|
|
|
@presenters[merge_request] ||= MergeRequestPresenter.new(merge_request, current_user: current_user) # rubocop: disable CodeReuse/Presenter
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
def can_add_ci_config_path?(merge_request)
|
|
|
|
merge_request.source_project&.uses_default_ci_config? &&
|
|
|
|
merge_request.all_pipelines.none? &&
|
|
|
|
merge_request.commits_count.positive? &&
|
|
|
|
can?(current_user, :push_code, merge_request.source_project)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
MergeRequestWidgetEntity.prepend_if_ee('EE::MergeRequestWidgetEntity')
|