2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-13 18:12:31 -04:00
|
|
|
class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationController
|
2016-03-15 12:18:47 -04:00
|
|
|
include ToggleSubscriptionAction
|
2016-03-21 09:12:52 -04:00
|
|
|
include IssuableActions
|
2017-03-30 23:06:09 -04:00
|
|
|
include RendersNotes
|
2017-08-23 12:53:29 -04:00
|
|
|
include RendersCommits
|
2019-09-24 14:06:05 -04:00
|
|
|
include RendersAssignees
|
2016-04-16 15:09:08 -04:00
|
|
|
include ToggleAwardEmoji
|
2016-07-23 19:28:12 -04:00
|
|
|
include IssuableCollections
|
2019-02-05 09:55:31 -05:00
|
|
|
include RecordUserLastActivity
|
2020-01-08 01:08:13 -05:00
|
|
|
include SourcegraphDecorator
|
2016-03-03 12:38:44 -05:00
|
|
|
|
2017-06-13 18:12:31 -04:00
|
|
|
skip_before_action :merge_request, only: [:index, :bulk_update]
|
2018-01-15 10:21:04 -05:00
|
|
|
before_action :whitelist_query_limiting, only: [:assign_related_issues, :update]
|
2017-11-01 13:35:14 -04:00
|
|
|
before_action :authorize_update_issuable!, only: [:close, :edit, :update, :remove_wip, :sort]
|
2020-05-13 05:08:37 -04:00
|
|
|
before_action :authorize_read_actual_head_pipeline!, only: [
|
|
|
|
:test_reports,
|
|
|
|
:exposed_artifacts,
|
|
|
|
:coverage_reports,
|
|
|
|
:terraform_reports,
|
|
|
|
:accessibility_reports
|
|
|
|
]
|
2017-11-07 08:34:12 -05:00
|
|
|
before_action :set_issuables_index, only: [:index]
|
2016-10-07 12:16:42 -04:00
|
|
|
before_action :authenticate_user!, only: [:assign_related_issues]
|
2017-12-20 04:01:21 -05:00
|
|
|
before_action :check_user_can_push_to_source_branch!, only: [:rebase]
|
2019-10-09 17:06:24 -04:00
|
|
|
before_action only: [:show] do
|
2020-02-17 19:09:20 -05:00
|
|
|
push_frontend_feature_flag(:diffs_batch_load, @project, default_enabled: true)
|
2020-03-10 11:08:08 -04:00
|
|
|
push_frontend_feature_flag(:deploy_from_footer, @project, default_enabled: true)
|
2020-03-13 17:09:38 -04:00
|
|
|
push_frontend_feature_flag(:single_mr_diff_view, @project, default_enabled: true)
|
2020-02-03 13:08:46 -05:00
|
|
|
push_frontend_feature_flag(:suggest_pipeline) if experiment_enabled?(:suggest_pipeline)
|
2020-04-09 02:09:30 -04:00
|
|
|
push_frontend_feature_flag(:code_navigation, @project)
|
2020-04-14 11:09:44 -04:00
|
|
|
push_frontend_feature_flag(:widget_visibility_polling, @project, default_enabled: true)
|
2020-04-21 11:21:10 -04:00
|
|
|
push_frontend_feature_flag(:merge_ref_head_comments, @project)
|
2020-05-13 14:08:47 -04:00
|
|
|
push_frontend_feature_flag(:mr_commit_neighbor_nav, @project, default_enabled: true)
|
2020-06-02 14:08:32 -04:00
|
|
|
push_frontend_feature_flag(:multiline_comments, @project)
|
2019-10-09 17:06:24 -04:00
|
|
|
end
|
2016-10-07 12:16:42 -04:00
|
|
|
|
2019-10-16 05:07:51 -04:00
|
|
|
before_action do
|
|
|
|
push_frontend_feature_flag(:vue_issuable_sidebar, @project.group)
|
|
|
|
end
|
|
|
|
|
2019-06-22 14:05:17 -04:00
|
|
|
around_action :allow_gitaly_ref_name_caching, only: [:index, :show, :discussions]
|
2019-04-04 16:22:11 -04:00
|
|
|
|
2011-11-28 02:39:43 -05:00
|
|
|
def index
|
2017-11-07 08:34:12 -05:00
|
|
|
@merge_requests = @issuables
|
2017-02-15 17:13:53 -05:00
|
|
|
|
2015-03-12 19:20:58 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
|
|
|
render json: {
|
2018-11-27 11:53:16 -05:00
|
|
|
html: view_to_html_string("projects/merge_requests/_merge_requests")
|
2015-03-12 19:20:58 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2011-11-28 02:39:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2018-06-05 07:43:29 -04:00
|
|
|
close_merge_request_if_no_source_project
|
2020-01-21 10:08:26 -05:00
|
|
|
@merge_request.check_mergeability(async: true)
|
2017-09-19 06:55:37 -04:00
|
|
|
|
2011-11-28 15:16:57 -05:00
|
|
|
respond_to do |format|
|
2017-05-09 00:15:34 -04:00
|
|
|
format.html do
|
2018-06-05 07:44:07 -04:00
|
|
|
# use next to appease Rubocop
|
|
|
|
next render('invalid') if target_branch_missing?
|
|
|
|
|
2019-09-24 14:06:05 -04:00
|
|
|
preload_assignees_for_render(@merge_request)
|
|
|
|
|
2017-06-13 18:12:31 -04:00
|
|
|
# Build a note object for comment form
|
|
|
|
@note = @project.notes.new(noteable: @merge_request)
|
|
|
|
|
|
|
|
@noteable = @merge_request
|
|
|
|
@commits_count = @merge_request.commits_count
|
2018-11-27 11:53:16 -05:00
|
|
|
@issuable_sidebar = serializer.represent(@merge_request, serializer: 'sidebar')
|
2019-08-28 17:09:22 -04:00
|
|
|
@current_user_data = UserSerializer.new(project: @project).represent(current_user, {}, MergeRequestUserEntity).to_json
|
2019-09-16 05:06:25 -04:00
|
|
|
@show_whitespace_default = current_user.nil? || current_user.show_whitespace_in_diffs
|
2020-03-17 14:09:44 -04:00
|
|
|
@coverage_path = coverage_reports_project_merge_request_path(@project, @merge_request, format: :json) if @merge_request.has_coverage_reports?
|
2017-06-13 18:12:31 -04:00
|
|
|
|
|
|
|
set_pipeline_variables
|
2017-09-19 06:55:37 -04:00
|
|
|
|
2018-02-07 05:29:01 -05:00
|
|
|
render
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
2016-06-28 12:25:32 -04:00
|
|
|
|
2016-07-03 17:01:13 -04:00
|
|
|
format.json do
|
2017-05-18 16:14:48 -04:00
|
|
|
Gitlab::PollingInterval.set_header(response, interval: 10_000)
|
|
|
|
|
2017-10-31 12:15:03 -04:00
|
|
|
render json: serializer.represent(@merge_request, serializer: params[:serializer])
|
2016-07-03 17:01:13 -04:00
|
|
|
end
|
|
|
|
|
2019-01-16 07:09:29 -05:00
|
|
|
format.patch do
|
2018-04-18 05:19:40 -04:00
|
|
|
break render_404 unless @merge_request.diff_refs
|
2016-07-03 17:01:13 -04:00
|
|
|
|
|
|
|
send_git_patch @project.repository, @merge_request.diff_refs
|
2016-06-10 08:57:50 -04:00
|
|
|
end
|
2016-07-03 17:01:13 -04:00
|
|
|
|
2016-05-12 14:50:49 -04:00
|
|
|
format.diff do
|
2018-04-18 05:19:40 -04:00
|
|
|
break render_404 unless @merge_request.diff_refs
|
2016-05-12 14:50:49 -04:00
|
|
|
|
2016-06-08 08:30:15 -04:00
|
|
|
send_git_diff @project.repository, @merge_request.diff_refs
|
2016-05-12 14:50:49 -04:00
|
|
|
end
|
2012-11-22 15:50:36 -05:00
|
|
|
end
|
2012-07-04 18:26:23 -04:00
|
|
|
end
|
|
|
|
|
2015-05-29 00:09:28 -04:00
|
|
|
def commits
|
2017-06-13 18:12:31 -04:00
|
|
|
# Get commits from repository
|
|
|
|
# or from cache if already merged
|
2017-11-10 14:57:11 -05:00
|
|
|
@commits =
|
2019-11-15 10:06:12 -05:00
|
|
|
set_commits_for_rendering(
|
|
|
|
@merge_request.recent_commits.with_latest_pipeline(@merge_request.source_branch),
|
|
|
|
commits_count: @merge_request.commits_count
|
|
|
|
)
|
2016-08-04 09:56:54 -04:00
|
|
|
|
2017-06-13 18:12:31 -04:00
|
|
|
render json: { html: view_to_html_string('projects/merge_requests/_commits') }
|
2016-07-27 12:54:04 -04:00
|
|
|
end
|
|
|
|
|
2016-07-22 20:28:39 -04:00
|
|
|
def pipelines
|
2019-06-28 10:40:34 -04:00
|
|
|
set_pipeline_variables
|
|
|
|
@pipelines = @pipelines.page(params[:page]).per(30)
|
2016-07-25 20:30:52 -04:00
|
|
|
|
2017-06-13 18:12:31 -04:00
|
|
|
Gitlab::PollingInterval.set_header(response, interval: 10_000)
|
2017-04-05 10:36:14 -04:00
|
|
|
|
2017-07-14 11:52:54 -04:00
|
|
|
render json: {
|
|
|
|
pipelines: PipelineSerializer
|
|
|
|
.new(project: @project, current_user: @current_user)
|
2018-10-30 11:56:30 -04:00
|
|
|
.with_pagination(request, response)
|
2017-07-14 11:52:54 -04:00
|
|
|
.represent(@pipelines),
|
|
|
|
count: {
|
|
|
|
all: @pipelines.count
|
|
|
|
}
|
|
|
|
}
|
2011-11-28 02:39:43 -05:00
|
|
|
end
|
|
|
|
|
2020-01-29 10:08:59 -05:00
|
|
|
def context_commits
|
|
|
|
return render_404 unless project.context_commits_enabled?
|
|
|
|
|
|
|
|
# Get commits from repository
|
|
|
|
# or from cache if already merged
|
|
|
|
commits = ContextCommitsFinder.new(project, @merge_request, { search: params[:search], limit: params[:limit], offset: params[:offset] }).execute
|
|
|
|
render json: CommitEntity.represent(commits, { type: :full, request: merge_request })
|
|
|
|
end
|
|
|
|
|
2018-08-02 02:05:07 -04:00
|
|
|
def test_reports
|
2019-04-16 07:06:52 -04:00
|
|
|
reports_response(@merge_request.compare_test_reports)
|
2018-08-02 02:05:07 -04:00
|
|
|
end
|
|
|
|
|
2020-05-13 05:08:37 -04:00
|
|
|
def accessibility_reports
|
|
|
|
if @merge_request.has_accessibility_reports?
|
|
|
|
reports_response(@merge_request.compare_accessibility_reports)
|
|
|
|
else
|
|
|
|
head :no_content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-17 14:09:44 -04:00
|
|
|
def coverage_reports
|
|
|
|
if @merge_request.has_coverage_reports?
|
|
|
|
reports_response(@merge_request.find_coverage_reports)
|
|
|
|
else
|
|
|
|
head :no_content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
def terraform_reports
|
|
|
|
reports_response(@merge_request.find_terraform_reports)
|
|
|
|
end
|
|
|
|
|
2019-10-21 11:05:58 -04:00
|
|
|
def exposed_artifacts
|
|
|
|
if @merge_request.has_exposed_artifacts?
|
|
|
|
reports_response(@merge_request.find_exposed_artifacts)
|
|
|
|
else
|
|
|
|
head :no_content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-08 07:04:24 -05:00
|
|
|
def edit
|
2017-06-13 18:12:31 -04:00
|
|
|
define_edit_vars
|
2015-12-08 07:04:24 -05:00
|
|
|
end
|
|
|
|
|
2011-11-28 02:39:43 -05:00
|
|
|
def update
|
2017-06-13 18:12:31 -04:00
|
|
|
@merge_request = ::MergeRequests::UpdateService.new(project, current_user, merge_request_params).execute(@merge_request)
|
2014-02-18 09:24:19 -05:00
|
|
|
|
2017-01-16 13:43:03 -05:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2018-10-12 11:06:56 -04:00
|
|
|
if @merge_request.errors.present?
|
2017-06-13 18:12:31 -04:00
|
|
|
define_edit_vars
|
|
|
|
|
2017-01-16 13:43:03 -05:00
|
|
|
render :edit
|
2018-10-12 11:06:56 -04:00
|
|
|
else
|
|
|
|
redirect_to project_merge_request_path(@merge_request.target_project, @merge_request)
|
2015-03-06 08:03:41 -05:00
|
|
|
end
|
2014-02-18 09:24:19 -05:00
|
|
|
end
|
2017-01-16 13:43:03 -05:00
|
|
|
|
|
|
|
format.json do
|
2018-10-12 11:06:56 -04:00
|
|
|
if merge_request.errors.present?
|
|
|
|
render json: @merge_request.errors, status: :bad_request
|
|
|
|
else
|
|
|
|
render json: serializer.represent(@merge_request, serializer: 'basic')
|
|
|
|
end
|
2017-01-16 13:43:03 -05:00
|
|
|
end
|
2011-11-28 02:39:43 -05:00
|
|
|
end
|
2016-08-01 11:34:17 -04:00
|
|
|
rescue ActiveRecord::StaleObjectError
|
2017-06-13 18:12:31 -04:00
|
|
|
define_edit_vars if request.format.html?
|
|
|
|
|
2017-01-16 13:43:03 -05:00
|
|
|
render_conflict_response
|
2011-11-28 02:39:43 -05:00
|
|
|
end
|
|
|
|
|
2016-02-26 22:34:32 -05:00
|
|
|
def remove_wip
|
2017-06-13 18:12:31 -04:00
|
|
|
@merge_request = ::MergeRequests::UpdateService
|
2017-05-09 00:15:34 -04:00
|
|
|
.new(project, current_user, wip_event: 'unwip')
|
|
|
|
.execute(@merge_request)
|
2016-02-26 22:34:32 -05:00
|
|
|
|
2017-12-07 16:56:59 -05:00
|
|
|
render json: serialize_widget(@merge_request)
|
2016-02-26 22:34:32 -05:00
|
|
|
end
|
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
def commit_change_content
|
|
|
|
render partial: 'projects/merge_requests/widget/commit_change_content', layout: false
|
2012-04-16 15:08:03 -04:00
|
|
|
end
|
|
|
|
|
2019-05-22 07:45:27 -04:00
|
|
|
def cancel_auto_merge
|
|
|
|
unless @merge_request.can_cancel_auto_merge?(current_user)
|
2016-10-27 08:04:43 -04:00
|
|
|
return access_denied!
|
|
|
|
end
|
2015-11-02 11:27:38 -05:00
|
|
|
|
2019-05-22 07:45:27 -04:00
|
|
|
AutoMergeService.new(project, current_user).cancel(@merge_request)
|
2017-05-09 00:15:34 -04:00
|
|
|
|
2017-12-07 16:56:59 -05:00
|
|
|
render json: serialize_widget(@merge_request)
|
2015-11-02 11:27:38 -05:00
|
|
|
end
|
|
|
|
|
2015-08-11 08:33:31 -04:00
|
|
|
def merge
|
2018-10-24 05:14:16 -04:00
|
|
|
access_check_result = merge_access_check
|
|
|
|
|
|
|
|
return access_check_result if access_check_result
|
2013-02-27 13:20:31 -05:00
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
status = merge!
|
2015-11-02 11:27:38 -05:00
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
if @merge_request.merge_error
|
|
|
|
render json: { status: status, merge_error: @merge_request.merge_error }
|
2012-04-16 16:05:08 -04:00
|
|
|
else
|
2017-05-09 00:15:34 -04:00
|
|
|
render json: { status: status }
|
2012-04-16 16:05:08 -04:00
|
|
|
end
|
2012-03-29 11:03:05 -04:00
|
|
|
end
|
|
|
|
|
2016-08-08 18:30:01 -04:00
|
|
|
def assign_related_issues
|
2017-06-13 18:12:31 -04:00
|
|
|
result = ::MergeRequests::AssignIssuesService.new(project, current_user, merge_request: @merge_request).execute
|
2016-08-08 18:30:01 -04:00
|
|
|
|
2017-06-13 18:12:31 -04:00
|
|
|
case result[:count]
|
|
|
|
when 0
|
|
|
|
flash[:error] = "Failed to assign you issues related to the merge request"
|
|
|
|
when 1
|
|
|
|
flash[:notice] = "1 issue has been assigned to you"
|
|
|
|
else
|
|
|
|
flash[:notice] = "#{result[:count]} issues have been assigned to you"
|
2016-08-08 18:30:01 -04:00
|
|
|
end
|
2017-06-13 18:12:31 -04:00
|
|
|
|
|
|
|
redirect_to(merge_request_path(@merge_request))
|
2016-08-08 18:30:01 -04:00
|
|
|
end
|
|
|
|
|
2017-03-17 02:58:12 -04:00
|
|
|
def pipeline_status
|
2017-02-27 14:17:21 -05:00
|
|
|
render json: PipelineSerializer
|
2017-05-09 00:15:34 -04:00
|
|
|
.new(project: @project, current_user: @current_user)
|
2019-07-22 14:16:15 -04:00
|
|
|
.represent_status(head_pipeline)
|
2017-02-27 14:17:21 -05:00
|
|
|
end
|
|
|
|
|
2016-10-07 18:10:06 -04:00
|
|
|
def ci_environments_status
|
2019-11-29 10:06:43 -05:00
|
|
|
environments =
|
|
|
|
if ci_environments_status_on_merge_result?
|
2020-01-09 22:07:46 -05:00
|
|
|
EnvironmentStatus.for_deployed_merge_request(@merge_request, current_user)
|
2019-11-29 10:06:43 -05:00
|
|
|
else
|
|
|
|
EnvironmentStatus.for_merge_request(@merge_request, current_user)
|
|
|
|
end
|
2016-10-05 07:52:15 -04:00
|
|
|
|
2018-10-09 12:17:40 -04:00
|
|
|
render json: EnvironmentStatusSerializer.new(current_user: current_user).represent(environments)
|
2012-12-10 22:14:05 -05:00
|
|
|
end
|
|
|
|
|
2017-12-20 04:01:21 -05:00
|
|
|
def rebase
|
2019-06-21 12:56:47 -04:00
|
|
|
@merge_request.rebase_async(current_user.id)
|
2017-12-20 04:01:21 -05:00
|
|
|
|
2018-11-22 12:47:29 -05:00
|
|
|
head :ok
|
2019-10-21 20:06:05 -04:00
|
|
|
rescue MergeRequest::RebaseLockTimeout => e
|
|
|
|
render json: { merge_error: e.message }, status: :conflict
|
2017-12-20 04:01:21 -05:00
|
|
|
end
|
|
|
|
|
2018-12-16 11:00:43 -05:00
|
|
|
def discussions
|
2019-09-16 11:06:26 -04:00
|
|
|
merge_request.discussions_diffs.load_highlight
|
2018-12-16 11:00:43 -05:00
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2011-11-28 02:39:43 -05:00
|
|
|
protected
|
|
|
|
|
2016-03-15 12:18:47 -04:00
|
|
|
alias_method :subscribable_resource, :merge_request
|
2016-03-21 09:12:52 -04:00
|
|
|
alias_method :issuable, :merge_request
|
2016-04-16 15:09:08 -04:00
|
|
|
alias_method :awardable, :merge_request
|
2011-12-15 16:57:46 -05:00
|
|
|
|
2019-08-21 06:13:45 -04:00
|
|
|
def sorting_field
|
2019-01-06 19:00:48 -05:00
|
|
|
MergeRequest::SORTING_PREFERENCE_FIELD
|
|
|
|
end
|
|
|
|
|
2015-11-02 11:27:38 -05:00
|
|
|
def merge_params
|
2017-06-21 11:30:45 -04:00
|
|
|
params.permit(merge_params_attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge_params_attributes
|
2019-11-15 10:06:12 -05:00
|
|
|
MergeRequest::KNOWN_MERGE_PARAMS
|
2015-11-02 11:27:38 -05:00
|
|
|
end
|
|
|
|
|
2019-05-22 07:45:27 -04:00
|
|
|
def auto_merge_requested?
|
|
|
|
# Support params[:merge_when_pipeline_succeeds] during the transition period
|
|
|
|
params[:auto_merge_strategy].present? || params[:merge_when_pipeline_succeeds].present?
|
2016-06-24 12:13:56 -04:00
|
|
|
end
|
2016-06-28 12:25:32 -04:00
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
private
|
|
|
|
|
2019-07-22 14:16:15 -04:00
|
|
|
def head_pipeline
|
|
|
|
strong_memoize(:head_pipeline) do
|
|
|
|
pipeline = @merge_request.head_pipeline
|
|
|
|
pipeline if can?(current_user, :read_pipeline, pipeline)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-29 07:34:41 -04:00
|
|
|
def ci_environments_status_on_merge_result?
|
|
|
|
params[:environment_target] == 'merge_commit'
|
|
|
|
end
|
|
|
|
|
2018-06-05 07:44:07 -04:00
|
|
|
def target_branch_missing?
|
|
|
|
@merge_request.has_no_commits? && !@merge_request.target_branch_exists?
|
|
|
|
end
|
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
def merge!
|
2019-05-22 07:45:27 -04:00
|
|
|
# Disable the CI check if auto_merge_strategy is specified since we have
|
2017-05-09 00:15:34 -04:00
|
|
|
# to wait until CI completes to know
|
2019-05-22 07:45:27 -04:00
|
|
|
unless @merge_request.mergeable?(skip_ci_check: auto_merge_requested?)
|
2017-05-09 00:15:34 -04:00
|
|
|
return :failed
|
|
|
|
end
|
|
|
|
|
2018-10-24 05:14:16 -04:00
|
|
|
merge_service = ::MergeRequests::MergeService.new(@project, current_user, merge_params)
|
|
|
|
|
|
|
|
unless merge_service.hooks_validation_pass?(@merge_request)
|
|
|
|
return :hook_validation_error
|
|
|
|
end
|
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
return :sha_mismatch if params[:sha] != @merge_request.diff_head_sha
|
|
|
|
|
2019-11-15 10:06:12 -05:00
|
|
|
@merge_request.update(merge_error: nil, squash: params.fetch(:squash, false))
|
2017-05-09 00:15:34 -04:00
|
|
|
|
2019-05-22 07:45:27 -04:00
|
|
|
if auto_merge_requested?
|
2019-06-06 03:25:06 -04:00
|
|
|
if merge_request.auto_merge_enabled?
|
|
|
|
# TODO: We should have a dedicated endpoint for updating merge params.
|
2019-09-18 10:02:45 -04:00
|
|
|
# See https://gitlab.com/gitlab-org/gitlab-foss/issues/63130.
|
2019-06-06 03:25:06 -04:00
|
|
|
AutoMergeService.new(project, current_user, merge_params).update(merge_request)
|
|
|
|
else
|
|
|
|
AutoMergeService.new(project, current_user, merge_params)
|
|
|
|
.execute(merge_request,
|
|
|
|
params[:auto_merge_strategy] || AutoMergeService::STRATEGY_MERGE_WHEN_PIPELINE_SUCCEEDS)
|
|
|
|
end
|
2017-05-09 00:15:34 -04:00
|
|
|
else
|
2018-05-30 12:18:04 -04:00
|
|
|
@merge_request.merge_async(current_user.id, merge_params)
|
2017-05-09 00:15:34 -04:00
|
|
|
|
|
|
|
:success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-07 16:56:59 -05:00
|
|
|
def serialize_widget(merge_request)
|
2020-04-21 11:21:10 -04:00
|
|
|
cached_data = serializer.represent(merge_request, serializer: 'poll_cached_widget')
|
|
|
|
widget_data = serializer.represent(merge_request, serializer: 'poll_widget')
|
|
|
|
cached_data.merge!(widget_data)
|
2017-12-07 16:56:59 -05:00
|
|
|
end
|
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
def serializer
|
2020-04-21 11:21:10 -04:00
|
|
|
@serializer ||= MergeRequestSerializer.new(current_user: current_user, project: merge_request.project)
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
2017-06-13 18:12:31 -04:00
|
|
|
|
|
|
|
def define_edit_vars
|
|
|
|
@source_project = @merge_request.source_project
|
|
|
|
@target_project = @merge_request.target_project
|
2018-09-12 12:39:34 -04:00
|
|
|
@noteable = @merge_request
|
2018-09-14 11:59:28 -04:00
|
|
|
|
|
|
|
# FIXME: We have to assign a presenter to another instance variable
|
|
|
|
# due to class_name checks being made with issuable classes
|
2018-09-07 08:29:19 -04:00
|
|
|
@mr_presenter = @merge_request.present(current_user: current_user)
|
2017-06-13 18:12:31 -04:00
|
|
|
end
|
2017-11-07 08:34:12 -05:00
|
|
|
|
2018-02-20 07:33:49 -05:00
|
|
|
def finder_type
|
|
|
|
MergeRequestsFinder
|
2017-11-07 08:34:12 -05:00
|
|
|
end
|
2017-12-20 04:01:21 -05:00
|
|
|
|
|
|
|
def check_user_can_push_to_source_branch!
|
|
|
|
return access_denied! unless @merge_request.source_branch_exists?
|
|
|
|
|
|
|
|
access_check = ::Gitlab::UserAccess
|
|
|
|
.new(current_user, project: @merge_request.source_project)
|
|
|
|
.can_push_to_branch?(@merge_request.source_branch)
|
|
|
|
|
|
|
|
access_denied! unless access_check
|
|
|
|
end
|
2018-01-15 10:21:04 -05:00
|
|
|
|
2018-10-24 05:14:16 -04:00
|
|
|
def merge_access_check
|
|
|
|
access_denied! unless @merge_request.can_be_merged_by?(current_user)
|
|
|
|
end
|
|
|
|
|
2018-01-15 10:21:04 -05:00
|
|
|
def whitelist_query_limiting
|
2019-09-18 10:02:45 -04:00
|
|
|
# Also see https://gitlab.com/gitlab-org/gitlab-foss/issues/42441
|
|
|
|
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-foss/issues/42438')
|
2018-01-15 10:21:04 -05:00
|
|
|
end
|
2019-04-16 07:06:52 -04:00
|
|
|
|
|
|
|
def reports_response(report_comparison)
|
|
|
|
case report_comparison[:status]
|
|
|
|
when :parsing
|
|
|
|
::Gitlab::PollingInterval.set_header(response, interval: 3000)
|
|
|
|
|
|
|
|
render json: '', status: :no_content
|
|
|
|
when :parsed
|
|
|
|
render json: report_comparison[:data].to_json, status: :ok
|
|
|
|
when :error
|
|
|
|
render json: { status_reason: report_comparison[:status_reason] }, status: :bad_request
|
|
|
|
else
|
2019-11-07 10:06:33 -05:00
|
|
|
raise "Failed to build comparison response as comparison yielded unknown status '#{report_comparison[:status]}'"
|
2019-04-16 07:06:52 -04:00
|
|
|
end
|
|
|
|
end
|
2019-08-21 01:42:28 -04:00
|
|
|
|
2019-10-21 11:05:58 -04:00
|
|
|
def authorize_read_actual_head_pipeline!
|
2019-08-21 01:42:28 -04:00
|
|
|
return render_404 unless can?(current_user, :read_build, merge_request.actual_head_pipeline)
|
|
|
|
end
|
2011-11-28 02:39:43 -05:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
Projects::MergeRequestsController.prepend_if_ee('EE::Projects::MergeRequestsController')
|