2018-07-19 18:43:13 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-09 21:01:55 +00:00
|
|
|
class MergeRequestWidgetEntity < Grape::Entity
|
|
|
|
include RequestAwareEntity
|
|
|
|
|
|
|
|
# Currently this attr is exposed to be used in app/assets/javascripts/notes/stores/getters.js
|
|
|
|
# in order to determine whether a noteable is an issue or an MR
|
2016-11-19 02:19:04 +00:00
|
|
|
expose :merge_params
|
2019-08-09 21:01:55 +00:00
|
|
|
|
2018-07-10 09:35:16 +00:00
|
|
|
expose :source_project_full_path do |merge_request|
|
|
|
|
merge_request.source_project&.full_path
|
|
|
|
end
|
2019-08-09 21:01:55 +00:00
|
|
|
|
2018-07-10 09:35:16 +00:00
|
|
|
expose :target_project_full_path do |merge_request|
|
|
|
|
merge_request.project&.full_path
|
|
|
|
end
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2019-08-09 21:01:55 +00:00
|
|
|
expose :email_patches_path do |merge_request|
|
|
|
|
project_merge_request_path(merge_request.project, merge_request, format: :patch)
|
2017-09-13 14:11:10 +00:00
|
|
|
end
|
|
|
|
|
2019-08-09 21:01:55 +00:00
|
|
|
expose :plain_diff_path do |merge_request|
|
|
|
|
project_merge_request_path(merge_request.project, merge_request, format: :diff)
|
2017-12-07 17:41:30 +00:00
|
|
|
end
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2019-08-09 21:01:55 +00:00
|
|
|
expose :merge_request_basic_path do |merge_request|
|
|
|
|
project_merge_request_path(merge_request.target_project, merge_request, serializer: :basic, format: :json)
|
2017-12-20 09:01:21 +00:00
|
|
|
end
|
2018-02-28 08:06:18 +00:00
|
|
|
|
2019-08-09 21:01:55 +00:00
|
|
|
expose :merge_request_widget_path do |merge_request|
|
|
|
|
widget_project_json_merge_request_path(merge_request.target_project, merge_request, format: :json)
|
2017-12-20 09:01:21 +00:00
|
|
|
end
|
|
|
|
|
2019-08-09 21:01:55 +00:00
|
|
|
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-05-09 04:15:34 +00:00
|
|
|
end
|
|
|
|
|
2019-08-09 21:01:55 +00:00
|
|
|
expose :create_note_path do |merge_request|
|
|
|
|
project_notes_path(merge_request.project, target_type: 'merge_request', target_id: merge_request.id)
|
2019-02-06 12:33:11 +00:00
|
|
|
end
|
|
|
|
|
2019-08-09 21:01:55 +00:00
|
|
|
expose :commit_change_content_path do |merge_request|
|
|
|
|
commit_change_content_project_merge_request_path(merge_request.project, merge_request)
|
2019-02-06 12:33:11 +00:00
|
|
|
end
|
|
|
|
|
2019-08-09 21:01:55 +00:00
|
|
|
expose :preview_note_path do |merge_request|
|
|
|
|
preview_markdown_path(merge_request.project, target_type: 'MergeRequest', target_id: merge_request.iid)
|
2018-01-30 01:53:47 +00:00
|
|
|
end
|
|
|
|
|
2019-08-09 21:01:55 +00:00
|
|
|
expose :conflicts_docs_path do |merge_request|
|
|
|
|
help_page_path('user/project/merge_requests/resolve_conflicts.md')
|
2017-05-09 04:15:34 +00:00
|
|
|
end
|
|
|
|
|
2019-08-09 21:01:55 +00:00
|
|
|
expose :merge_request_pipelines_docs_path do |merge_request|
|
|
|
|
help_page_path('ci/merge_request_pipelines/index.md')
|
2017-05-09 04:15:34 +00:00
|
|
|
end
|
|
|
|
|
2019-08-09 21:01:55 +00:00
|
|
|
expose :ci_environments_status_path do |merge_request|
|
|
|
|
ci_environments_status_project_merge_request_path(merge_request.project, merge_request)
|
2017-05-09 04:15:34 +00:00
|
|
|
end
|
|
|
|
|
2019-06-20 22:18:51 +00:00
|
|
|
# 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-05-09 04:15:34 +00:00
|
|
|
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
|
|
|
|
|
2019-08-09 21:01:55 +00:00
|
|
|
def as_json(options = {})
|
|
|
|
super(options)
|
|
|
|
.merge(MergeRequestPollCachedWidgetEntity.new(object, **@options.opts_hash).as_json(options))
|
|
|
|
.merge(MergeRequestPollWidgetEntity.new(object, **@options.opts_hash).as_json(options))
|
2019-04-15 13:25:48 +00:00
|
|
|
end
|
|
|
|
|
2017-05-09 04:15:34 +00:00
|
|
|
private
|
|
|
|
|
2019-08-22 13:50:19 +00:00
|
|
|
delegate :current_user, to: :request
|
|
|
|
|
2017-05-09 04:15:34 +00:00
|
|
|
def presenter(merge_request)
|
|
|
|
@presenters ||= {}
|
2019-08-22 13:50:19 +00:00
|
|
|
@presenters[merge_request] ||= MergeRequestPresenter.new(merge_request, current_user: current_user) # rubocop: disable CodeReuse/Presenter
|
2017-12-07 17:41:30 +00:00
|
|
|
end
|
2016-11-19 02:19:04 +00:00
|
|
|
end
|