2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-13 18:12:31 -04:00
|
|
|
class Projects::MergeRequests::CreationsController < Projects::MergeRequests::ApplicationController
|
|
|
|
include DiffForPath
|
|
|
|
include DiffHelper
|
2017-08-23 12:53:29 -04:00
|
|
|
include RendersCommits
|
2017-06-13 18:12:31 -04:00
|
|
|
|
|
|
|
skip_before_action :merge_request
|
2018-04-06 08:18:58 -04:00
|
|
|
before_action :authorize_create_merge_request_from!
|
2017-06-13 18:12:31 -04:00
|
|
|
before_action :apply_diff_view_cookie!, only: [:diffs, :diff_for_path]
|
|
|
|
before_action :build_merge_request, except: [:create]
|
|
|
|
|
2020-12-01 10:09:28 -05:00
|
|
|
before_action do
|
|
|
|
push_frontend_feature_flag(:mr_collapsed_approval_rules, @project)
|
|
|
|
end
|
|
|
|
|
2017-06-13 18:12:31 -04:00
|
|
|
def new
|
2019-12-30 07:09:15 -05:00
|
|
|
define_new_vars
|
2017-06-13 18:12:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@merge_request = ::MergeRequests::CreateService.new(project, current_user, merge_request_params).execute
|
|
|
|
|
|
|
|
if @merge_request.valid?
|
2019-07-19 07:11:27 -04:00
|
|
|
incr_count_webide_merge_request
|
|
|
|
|
2017-06-13 18:12:31 -04:00
|
|
|
redirect_to(merge_request_path(@merge_request))
|
|
|
|
else
|
|
|
|
@source_project = @merge_request.source_project
|
|
|
|
@target_project = @merge_request.target_project
|
|
|
|
|
|
|
|
define_new_vars
|
|
|
|
render action: "new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def pipelines
|
2020-07-15 17:09:26 -04:00
|
|
|
@pipelines = Ci::PipelinesForMergeRequestFinder.new(@merge_request, current_user).execute
|
2017-06-13 18:12:31 -04:00
|
|
|
|
|
|
|
Gitlab::PollingInterval.set_header(response, interval: 10_000)
|
|
|
|
|
|
|
|
render json: {
|
|
|
|
pipelines: PipelineSerializer
|
2020-07-15 17:09:26 -04:00
|
|
|
.new(project: @project, current_user: current_user)
|
2017-06-13 18:12:31 -04:00
|
|
|
.represent(@pipelines)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def diffs
|
2018-01-11 15:18:01 -05:00
|
|
|
@diffs = @merge_request.diffs(diff_options) if @merge_request.can_be_created
|
2018-01-11 11:34:01 -05:00
|
|
|
|
2017-06-13 18:12:31 -04:00
|
|
|
@diff_notes_disabled = true
|
|
|
|
|
2019-12-18 13:08:04 -05:00
|
|
|
@environment = @merge_request.environments_for(current_user, latest: true).last
|
2017-06-13 18:12:31 -04:00
|
|
|
|
|
|
|
render json: { html: view_to_html_string('projects/merge_requests/creations/_diffs', diffs: @diffs, environment: @environment) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def diff_for_path
|
|
|
|
@diffs = @merge_request.diffs(diff_options)
|
|
|
|
@diff_notes_disabled = true
|
|
|
|
|
|
|
|
render_diff_for_path(@diffs)
|
|
|
|
end
|
|
|
|
|
|
|
|
def branch_from
|
|
|
|
# This is always source
|
|
|
|
@source_project = @merge_request.nil? ? @project : @merge_request.source_project
|
|
|
|
|
|
|
|
if params[:ref].present?
|
|
|
|
@ref = params[:ref]
|
2017-11-24 06:58:05 -05:00
|
|
|
@commit = @repository.commit(Gitlab::Git::BRANCH_REF_PREFIX + @ref)
|
2017-06-13 18:12:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
render layout: false
|
|
|
|
end
|
|
|
|
|
|
|
|
def branch_to
|
|
|
|
@target_project = selected_target_project
|
|
|
|
|
2017-12-11 09:21:06 -05:00
|
|
|
if @target_project && params[:ref].present?
|
2017-06-13 18:12:31 -04:00
|
|
|
@ref = params[:ref]
|
2017-11-24 06:58:05 -05:00
|
|
|
@commit = @target_project.commit(Gitlab::Git::BRANCH_REF_PREFIX + @ref)
|
2017-06-13 18:12:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
render layout: false
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def build_merge_request
|
|
|
|
params[:merge_request] ||= ActionController::Parameters.new(source_project: @project)
|
2019-02-22 16:10:06 -05:00
|
|
|
|
2019-09-18 10:02:45 -04:00
|
|
|
# Gitaly N+1 issue: https://gitlab.com/gitlab-org/gitlab-foss/issues/58096
|
2019-02-22 16:10:06 -05:00
|
|
|
Gitlab::GitalyClient.allow_n_plus_1_calls do
|
|
|
|
@merge_request = ::MergeRequests::BuildService.new(project, current_user, merge_request_params.merge(diff_options: diff_options)).execute
|
|
|
|
end
|
2017-06-13 18:12:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def define_new_vars
|
|
|
|
@noteable = @merge_request
|
|
|
|
@target_project = @merge_request.target_project
|
|
|
|
@source_project = @merge_request.source_project
|
2019-11-15 10:06:12 -05:00
|
|
|
|
|
|
|
@commits =
|
|
|
|
set_commits_for_rendering(
|
|
|
|
@merge_request.recent_commits.with_latest_pipeline(@merge_request.source_branch),
|
|
|
|
commits_count: @merge_request.commits_count
|
|
|
|
)
|
|
|
|
|
2017-06-13 18:12:31 -04:00
|
|
|
@commit = @merge_request.diff_head_commit
|
|
|
|
|
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
|
|
|
|
|
|
|
@labels = LabelsFinder.new(current_user, project_id: @project.id).execute
|
|
|
|
|
|
|
|
set_pipeline_variables
|
|
|
|
end
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-06-13 18:12:31 -04:00
|
|
|
def selected_target_project
|
2017-09-21 12:34:32 -04:00
|
|
|
if @project.id.to_s == params[:target_project_id] || !@project.forked?
|
2017-06-13 18:12:31 -04:00
|
|
|
@project
|
2017-09-21 12:34:32 -04:00
|
|
|
elsif params[:target_project_id].present?
|
|
|
|
MergeRequestTargetProjectFinder.new(current_user: current_user, source_project: @project)
|
2017-12-11 09:21:06 -05:00
|
|
|
.find_by(id: params[:target_project_id])
|
2017-06-13 18:12:31 -04:00
|
|
|
else
|
2017-09-21 12:34:32 -04:00
|
|
|
@project.forked_from_project
|
2017-06-13 18:12:31 -04:00
|
|
|
end
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-01-15 10:21:04 -05:00
|
|
|
|
2019-07-19 07:11:27 -04:00
|
|
|
def incr_count_webide_merge_request
|
|
|
|
return if params[:nav_source] != 'webide'
|
|
|
|
|
|
|
|
Gitlab::UsageDataCounters::WebIdeCounter.increment_merge_requests_count
|
|
|
|
end
|
2017-06-13 18:12:31 -04:00
|
|
|
end
|
2021-04-01 05:09:05 -04:00
|
|
|
|
|
|
|
Projects::MergeRequests::CreationsController.prepend_ee_mod
|