2019-09-30 21:07:59 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Projects::MergeRequests::ContentController < Projects::MergeRequests::ApplicationController
|
|
|
|
# @merge_request.check_mergeability is not executed here since
|
|
|
|
# widget serializer calls it via mergeable? method
|
|
|
|
# but we might want to call @merge_request.check_mergeability
|
|
|
|
# for other types of serialization
|
|
|
|
|
|
|
|
before_action :close_merge_request_if_no_source_project
|
2019-10-12 21:52:04 +05:30
|
|
|
before_action :set_polling_header
|
2019-09-30 21:07:59 +05:30
|
|
|
around_action :allow_gitaly_ref_name_caching
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
FAST_POLLING_INTERVAL = 10.seconds.in_milliseconds
|
|
|
|
SLOW_POLLING_INTERVAL = 5.minutes.in_milliseconds
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
def widget
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
2019-10-12 21:52:04 +05:30
|
|
|
render json: serializer(MergeRequestPollWidgetEntity)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
def cached_widget
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: serializer(MergeRequestPollCachedWidgetEntity)
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_polling_header
|
2020-11-24 15:15:51 +05:30
|
|
|
interval = merge_request.open? ? FAST_POLLING_INTERVAL : SLOW_POLLING_INTERVAL
|
|
|
|
Gitlab::PollingInterval.set_header(response, interval: interval)
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def serializer(entity)
|
|
|
|
serializer = MergeRequestSerializer.new(current_user: current_user, project: merge_request.project)
|
2021-09-04 01:27:46 +05:30
|
|
|
serializer.represent(merge_request, {}, entity)
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|