2013-06-23 12:47:22 -04:00
|
|
|
class Projects::MergeRequestsController < Projects::ApplicationController
|
2016-03-15 12:18:47 -04:00
|
|
|
include ToggleSubscriptionAction
|
2016-07-06 13:15:27 -04:00
|
|
|
include DiffForPath
|
2016-03-03 12:38:44 -05:00
|
|
|
include DiffHelper
|
2016-03-21 09:12:52 -04:00
|
|
|
include IssuableActions
|
2016-07-20 00:52:31 -04:00
|
|
|
include NotesHelper
|
2016-04-16 15:09:08 -04:00
|
|
|
include ToggleAwardEmoji
|
2016-07-23 19:28:12 -04:00
|
|
|
include IssuableCollections
|
2016-03-03 12:38:44 -05:00
|
|
|
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :module_enabled
|
2015-05-29 00:09:28 -04:00
|
|
|
before_action :merge_request, only: [
|
2016-08-17 13:21:30 -04:00
|
|
|
:edit, :update, :show, :diffs, :commits, :conflicts, :builds, :pipelines, :merge, :merge_check,
|
2016-08-04 09:32:10 -04:00
|
|
|
:ci_status, :toggle_subscription, :cancel_merge_when_build_succeeds, :remove_wip, :resolve_conflicts
|
2015-05-29 00:09:28 -04:00
|
|
|
]
|
2016-07-22 20:28:39 -04:00
|
|
|
before_action :validates_merge_request, only: [:show, :diffs, :commits, :builds, :pipelines]
|
2016-08-17 13:21:30 -04:00
|
|
|
before_action :define_show_vars, only: [:show, :diffs, :commits, :conflicts, :builds, :pipelines]
|
2015-12-16 09:20:53 -05:00
|
|
|
before_action :define_widget_vars, only: [:merge, :cancel_merge_when_build_succeeds, :merge_check]
|
2016-06-28 12:25:32 -04:00
|
|
|
before_action :define_commit_vars, only: [:diffs]
|
|
|
|
before_action :define_diff_comment_vars, only: [:diffs]
|
2016-08-17 13:21:30 -04:00
|
|
|
before_action :ensure_ref_fetched, only: [:show, :diffs, :commits, :builds, :conflicts, :pipelines]
|
2011-12-15 16:57:46 -05:00
|
|
|
|
|
|
|
# Allow read any merge_request
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :authorize_read_merge_request!
|
2011-12-15 16:57:46 -05:00
|
|
|
|
|
|
|
# Allow write(create) merge_request
|
2015-06-26 10:44:21 -04:00
|
|
|
before_action :authorize_create_merge_request!, only: [:new, :create]
|
2011-12-15 16:57:46 -05:00
|
|
|
|
|
|
|
# Allow modify merge_request
|
2016-02-26 22:34:32 -05:00
|
|
|
before_action :authorize_update_merge_request!, only: [:close, :edit, :update, :remove_wip, :sort]
|
2011-12-15 16:57:46 -05:00
|
|
|
|
2016-08-10 23:36:58 -04:00
|
|
|
before_action :authorize_can_resolve_conflicts!, only: [:conflicts, :resolve_conflicts]
|
|
|
|
|
2011-11-28 02:39:43 -05:00
|
|
|
def index
|
2015-03-12 19:20:58 -04:00
|
|
|
terms = params['issue_search']
|
2016-07-23 19:28:12 -04:00
|
|
|
@merge_requests = merge_requests_collection
|
2015-05-17 13:32:58 -04:00
|
|
|
|
|
|
|
if terms.present?
|
|
|
|
if terms =~ /\A[#!](\d+)\z/
|
|
|
|
@merge_requests = @merge_requests.where(iid: $1)
|
|
|
|
else
|
|
|
|
@merge_requests = @merge_requests.full_search(terms)
|
|
|
|
end
|
|
|
|
end
|
2015-05-29 00:09:28 -04:00
|
|
|
|
2016-03-19 17:37:54 -04:00
|
|
|
@merge_requests = @merge_requests.page(params[:page])
|
2015-11-03 09:44:14 -05:00
|
|
|
@merge_requests = @merge_requests.preload(:target_project)
|
2015-03-12 19:20:58 -04:00
|
|
|
|
2016-04-20 08:55:19 -04:00
|
|
|
@labels = @project.labels.where(title: params[:label_name])
|
2016-02-17 08:52:12 -05:00
|
|
|
|
2015-03-12 19:20:58 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
|
|
|
render json: {
|
2016-04-20 08:55:19 -04:00
|
|
|
html: view_to_html_string("projects/merge_requests/_merge_requests"),
|
2016-04-20 12:00:12 -04:00
|
|
|
labels: @labels.as_json(methods: :text_color)
|
2015-03-12 19:20:58 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2011-11-28 02:39:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2011-11-28 15:16:57 -05:00
|
|
|
respond_to do |format|
|
2016-07-12 08:29:26 -04:00
|
|
|
format.html { define_discussion_vars }
|
2016-06-28 12:25:32 -04:00
|
|
|
|
2016-07-03 17:01:13 -04:00
|
|
|
format.json do
|
|
|
|
render json: @merge_request
|
|
|
|
end
|
|
|
|
|
2016-06-10 08:57:50 -04:00
|
|
|
format.patch do
|
2016-07-03 17:01:13 -04:00
|
|
|
return render_404 unless @merge_request.diff_refs
|
|
|
|
|
|
|
|
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
|
2016-06-08 08:30:15 -04:00
|
|
|
return 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
|
|
|
|
|
2011-11-28 15:16:57 -05:00
|
|
|
def diffs
|
2015-10-22 21:52:17 -04:00
|
|
|
apply_diff_view_cookie!
|
|
|
|
|
2016-07-07 04:32:01 -04:00
|
|
|
@merge_request_diff = @merge_request.merge_request_diff
|
|
|
|
|
2013-12-02 07:27:36 -05:00
|
|
|
respond_to do |format|
|
2016-07-12 08:29:26 -04:00
|
|
|
format.html { define_discussion_vars }
|
2016-07-26 03:21:42 -04:00
|
|
|
format.json do
|
2016-07-27 13:00:34 -04:00
|
|
|
@diffs = @merge_request.diffs(diff_options)
|
2016-07-26 03:21:42 -04:00
|
|
|
|
|
|
|
render json: { html: view_to_html_string("projects/merge_requests/show/_diffs") }
|
|
|
|
end
|
2013-12-02 07:27:36 -05:00
|
|
|
end
|
2011-11-28 02:39:43 -05:00
|
|
|
end
|
|
|
|
|
2016-06-28 12:25:32 -04:00
|
|
|
# With an ID param, loads the MR at that ID. Otherwise, accepts the same params as #new
|
|
|
|
# and uses that (unsaved) MR.
|
|
|
|
#
|
|
|
|
def diff_for_path
|
|
|
|
if params[:id]
|
|
|
|
merge_request
|
|
|
|
define_diff_comment_vars
|
|
|
|
else
|
|
|
|
build_merge_request
|
|
|
|
@diff_notes_disabled = true
|
2016-07-20 18:18:18 -04:00
|
|
|
@grouped_diff_discussions = {}
|
2016-06-28 12:25:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
define_commit_vars
|
|
|
|
|
2016-07-27 13:00:34 -04:00
|
|
|
render_diff_for_path(@merge_request.diffs(diff_options))
|
2016-06-28 12:25:32 -04:00
|
|
|
end
|
|
|
|
|
2015-05-29 00:09:28 -04:00
|
|
|
def commits
|
2015-06-17 16:12:28 -04:00
|
|
|
respond_to do |format|
|
2016-07-12 08:29:26 -04:00
|
|
|
format.html do
|
|
|
|
define_discussion_vars
|
|
|
|
|
|
|
|
render 'show'
|
|
|
|
end
|
2016-07-07 04:32:01 -04:00
|
|
|
format.json do
|
|
|
|
# Get commits from repository
|
|
|
|
# or from cache if already merged
|
|
|
|
@commits = @merge_request.commits
|
|
|
|
@note_counts = Note.where(commit_id: @commits.map(&:id)).
|
|
|
|
group(:commit_id).count
|
|
|
|
|
|
|
|
render json: { html: view_to_html_string('projects/merge_requests/show/_commits') }
|
|
|
|
end
|
2015-06-17 16:12:28 -04:00
|
|
|
end
|
2015-05-29 00:09:28 -04:00
|
|
|
end
|
|
|
|
|
2016-07-11 12:16:42 -04:00
|
|
|
def conflicts
|
|
|
|
respond_to do |format|
|
2016-08-01 10:22:26 -04:00
|
|
|
format.html { define_discussion_vars }
|
2016-07-29 06:16:31 -04:00
|
|
|
|
2016-07-29 09:51:11 -04:00
|
|
|
format.json do
|
2016-08-10 23:36:13 -04:00
|
|
|
if @merge_request.conflicts_can_be_resolved_in_ui?
|
2016-08-04 05:31:44 -04:00
|
|
|
render json: @merge_request.conflicts
|
2016-08-10 23:38:08 -04:00
|
|
|
elsif @merge_request.can_be_merged?
|
|
|
|
render json: {
|
|
|
|
message: 'The merge conflicts for this merge request have already been resolved. Please return to the merge request.',
|
|
|
|
type: 'error'
|
|
|
|
}
|
2016-08-04 05:31:44 -04:00
|
|
|
else
|
2016-08-02 07:51:43 -04:00
|
|
|
render json: {
|
2016-08-10 23:38:08 -04:00
|
|
|
message: 'The merge conflicts for this merge request cannot be resolved through GitLab. Please try to resolve them locally.',
|
2016-08-02 07:51:43 -04:00
|
|
|
type: 'error'
|
|
|
|
}
|
2016-07-29 09:51:11 -04:00
|
|
|
end
|
|
|
|
end
|
2016-07-11 12:16:42 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-27 12:54:04 -04:00
|
|
|
def resolve_conflicts
|
2016-08-10 23:38:08 -04:00
|
|
|
return render_404 unless @merge_request.conflicts_can_be_resolved_in_ui?
|
|
|
|
|
|
|
|
if @merge_request.can_be_merged?
|
|
|
|
render status: :bad_request, json: { message: 'The merge conflicts for this merge request have already been resolved.' }
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2016-07-29 09:51:11 -04:00
|
|
|
begin
|
2016-08-10 23:40:43 -04:00
|
|
|
MergeRequests::ResolveService.new(@merge_request.source_project, current_user, params).execute(@merge_request)
|
2016-07-27 12:54:04 -04:00
|
|
|
|
2016-08-10 23:42:10 -04:00
|
|
|
flash[:notice] = 'All merge conflicts were resolved. The merge request can now be merged.'
|
2016-08-04 09:56:54 -04:00
|
|
|
|
2016-08-10 23:41:48 -04:00
|
|
|
render json: { redirect_to: namespace_project_merge_request_url(@project.namespace, @project, @merge_request, resolved_conflicts: true) }
|
2016-07-29 09:51:11 -04:00
|
|
|
rescue Gitlab::Conflict::File::MissingResolution => e
|
|
|
|
render status: :bad_request, json: { message: e.message }
|
|
|
|
end
|
2016-07-27 12:54:04 -04:00
|
|
|
end
|
|
|
|
|
2015-12-08 07:04:24 -05:00
|
|
|
def builds
|
|
|
|
respond_to do |format|
|
2016-07-12 08:29:26 -04:00
|
|
|
format.html do
|
|
|
|
define_discussion_vars
|
|
|
|
|
|
|
|
render 'show'
|
|
|
|
end
|
2015-12-08 07:04:24 -05:00
|
|
|
format.json { render json: { html: view_to_html_string('projects/merge_requests/show/_builds') } }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-22 20:28:39 -04:00
|
|
|
def pipelines
|
2016-08-12 10:22:48 -04:00
|
|
|
@pipelines = @merge_request.all_pipelines
|
2016-07-25 20:30:52 -04:00
|
|
|
|
2016-07-22 20:28:39 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
define_discussion_vars
|
|
|
|
|
|
|
|
render 'show'
|
|
|
|
end
|
|
|
|
format.json { render json: { html: view_to_html_string('projects/merge_requests/show/_pipelines') } }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-28 02:39:43 -05:00
|
|
|
def new
|
2016-08-11 04:02:27 -04:00
|
|
|
apply_diff_view_cookie!
|
|
|
|
|
2016-06-28 12:25:32 -04:00
|
|
|
build_merge_request
|
2016-01-15 05:29:53 -05:00
|
|
|
@noteable = @merge_request
|
2014-07-15 08:34:06 -04:00
|
|
|
|
|
|
|
@target_branches = if @merge_request.target_project
|
|
|
|
@merge_request.target_project.repository.branch_names
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
|
|
|
@target_project = merge_request.target_project
|
|
|
|
@source_project = merge_request.source_project
|
2015-12-08 07:04:24 -05:00
|
|
|
@commits = @merge_request.compare_commits.reverse
|
2016-06-20 12:48:04 -04:00
|
|
|
@commit = @merge_request.diff_head_commit
|
2016-01-20 12:44:27 -05:00
|
|
|
@base_commit = @merge_request.diff_base_commit
|
2016-07-27 13:00:34 -04:00
|
|
|
@diffs = @merge_request.diffs(diff_options) if @merge_request.compare
|
2016-05-13 15:53:04 -04:00
|
|
|
@diff_notes_disabled = true
|
2016-06-02 10:19:18 -04:00
|
|
|
@pipeline = @merge_request.pipeline
|
2016-08-11 09:22:35 -04:00
|
|
|
@statuses = @pipeline.statuses.relevant if @pipeline
|
2015-12-08 07:04:24 -05:00
|
|
|
|
2014-07-15 08:34:06 -04:00
|
|
|
@note_counts = Note.where(commit_id: @commits.map(&:id)).
|
|
|
|
group(:commit_id).count
|
2011-11-28 02:39:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2013-04-25 10:15:33 -04:00
|
|
|
@target_branches ||= []
|
2014-06-26 07:30:07 -04:00
|
|
|
@merge_request = MergeRequests::CreateService.new(project, current_user, merge_request_params).execute
|
2014-04-02 14:51:53 -04:00
|
|
|
|
|
|
|
if @merge_request.valid?
|
2015-03-11 19:07:33 -04:00
|
|
|
redirect_to(merge_request_path(@merge_request))
|
2012-06-13 02:03:53 -04:00
|
|
|
else
|
2013-06-08 11:51:18 -04:00
|
|
|
@source_project = @merge_request.source_project
|
|
|
|
@target_project = @merge_request.target_project
|
|
|
|
render action: "new"
|
2011-11-28 02:39:43 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-08 07:04:24 -05:00
|
|
|
def edit
|
|
|
|
@source_project = @merge_request.source_project
|
|
|
|
@target_project = @merge_request.target_project
|
|
|
|
@target_branches = @merge_request.target_project.repository.branch_names
|
|
|
|
end
|
|
|
|
|
2011-11-28 02:39:43 -05:00
|
|
|
def update
|
2014-06-26 07:30:07 -04:00
|
|
|
@merge_request = MergeRequests::UpdateService.new(project, current_user, merge_request_params).execute(@merge_request)
|
2014-02-18 09:24:19 -05:00
|
|
|
|
2014-04-02 14:51:53 -04:00
|
|
|
if @merge_request.valid?
|
2014-02-18 09:24:19 -05:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to([@merge_request.target_project.namespace.becomes(Namespace),
|
2015-03-11 19:07:33 -04:00
|
|
|
@merge_request.target_project, @merge_request])
|
2014-02-18 09:24:19 -05:00
|
|
|
end
|
2015-03-06 08:03:41 -05:00
|
|
|
format.json do
|
2016-04-22 08:30:58 -04:00
|
|
|
render json: @merge_request.to_json(include: { milestone: {}, assignee: { methods: :avatar_url }, labels: { methods: :text_color } })
|
2015-03-06 08:03:41 -05:00
|
|
|
end
|
2014-02-18 09:24:19 -05:00
|
|
|
end
|
2012-06-13 02:03:53 -04:00
|
|
|
else
|
2013-06-22 08:08:11 -04:00
|
|
|
render "edit"
|
2011-11-28 02:39:43 -05:00
|
|
|
end
|
2016-08-01 11:34:17 -04:00
|
|
|
rescue ActiveRecord::StaleObjectError
|
|
|
|
@conflict = true
|
|
|
|
render :edit
|
2011-11-28 02:39:43 -05:00
|
|
|
end
|
|
|
|
|
2016-02-26 22:34:32 -05:00
|
|
|
def remove_wip
|
|
|
|
MergeRequests::UpdateService.new(project, current_user, title: @merge_request.wipless_title).execute(@merge_request)
|
|
|
|
|
|
|
|
redirect_to namespace_project_merge_request_path(@project.namespace, @project, @merge_request),
|
|
|
|
notice: "The merge request can now be merged."
|
|
|
|
end
|
|
|
|
|
2015-08-11 08:33:31 -04:00
|
|
|
def merge_check
|
2016-01-05 10:24:42 -05:00
|
|
|
@merge_request.check_if_can_be_merged
|
2015-06-11 09:14:50 -04:00
|
|
|
|
2015-06-11 12:35:43 -04:00
|
|
|
render partial: "projects/merge_requests/widget/show.html.haml", layout: false
|
2012-04-16 15:08:03 -04:00
|
|
|
end
|
|
|
|
|
2015-11-02 11:27:38 -05:00
|
|
|
def cancel_merge_when_build_succeeds
|
2015-11-23 03:42:20 -05:00
|
|
|
return access_denied! unless @merge_request.can_cancel_merge_when_build_succeeds?(current_user)
|
2015-11-02 11:27:38 -05:00
|
|
|
|
2015-11-23 03:42:20 -05:00
|
|
|
MergeRequests::MergeWhenBuildSucceedsService.new(@project, current_user).cancel(@merge_request)
|
2015-11-02 11:27:38 -05:00
|
|
|
end
|
|
|
|
|
2015-08-11 08:33:31 -04:00
|
|
|
def merge
|
2015-06-11 12:45:12 -04:00
|
|
|
return access_denied! unless @merge_request.can_be_merged_by?(current_user)
|
2013-02-27 13:20:31 -05:00
|
|
|
|
2016-06-24 12:13:56 -04:00
|
|
|
# Disable the CI check if merge_when_build_succeeds is enabled since we have
|
|
|
|
# to wait until CI completes to know
|
|
|
|
unless @merge_request.mergeable?(skip_ci_check: merge_when_build_succeeds_active?)
|
2015-11-02 11:27:38 -05:00
|
|
|
@status = :failed
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2016-06-20 12:48:04 -04:00
|
|
|
if params[:sha] != @merge_request.diff_head_sha
|
2016-06-01 08:25:44 -04:00
|
|
|
@status = :sha_mismatch
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
TodoService.new.merge_merge_request(merge_request, current_user)
|
2016-02-18 18:53:22 -05:00
|
|
|
|
2015-11-02 11:27:38 -05:00
|
|
|
@merge_request.update(merge_error: nil)
|
|
|
|
|
2016-06-22 15:58:29 -04:00
|
|
|
if params[:merge_when_build_succeeds].present?
|
|
|
|
unless @merge_request.pipeline
|
|
|
|
@status = :failed
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if @merge_request.pipeline.active?
|
2016-06-02 15:36:10 -04:00
|
|
|
MergeRequests::MergeWhenBuildSucceedsService.new(@project, current_user, merge_params)
|
|
|
|
.execute(@merge_request)
|
|
|
|
@status = :merge_when_build_succeeds
|
2016-06-09 05:54:48 -04:00
|
|
|
elsif @merge_request.pipeline.success?
|
|
|
|
# This can be triggered when a user clicks the auto merge button while
|
|
|
|
# the tests finish at about the same time
|
2016-06-02 15:36:10 -04:00
|
|
|
MergeWorker.perform_async(@merge_request.id, current_user.id, params)
|
|
|
|
@status = :success
|
|
|
|
else
|
|
|
|
@status = :failed
|
|
|
|
end
|
2012-04-16 16:05:08 -04:00
|
|
|
else
|
2015-11-02 11:27:38 -05:00
|
|
|
MergeWorker.perform_async(@merge_request.id, current_user.id, params)
|
|
|
|
@status = :success
|
2012-04-16 16:05:08 -04:00
|
|
|
end
|
2012-03-29 11:03:05 -04:00
|
|
|
end
|
|
|
|
|
2012-03-13 17:54:49 -04:00
|
|
|
def branch_from
|
2016-05-31 18:33:46 -04:00
|
|
|
# This is always source
|
2013-06-03 16:20:50 -04:00
|
|
|
@source_project = @merge_request.nil? ? @project : @merge_request.source_project
|
2013-08-08 08:14:59 -04:00
|
|
|
@commit = @repository.commit(params[:ref]) if params[:ref].present?
|
2016-03-15 10:43:40 -04:00
|
|
|
render layout: false
|
2012-03-13 17:54:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def branch_to
|
2013-04-25 10:15:33 -04:00
|
|
|
@target_project = selected_target_project
|
2015-04-21 09:13:40 -04:00
|
|
|
@commit = @target_project.commit(params[:ref]) if params[:ref].present?
|
2016-03-15 10:43:40 -04:00
|
|
|
render layout: false
|
2012-03-13 17:54:49 -04:00
|
|
|
end
|
|
|
|
|
2013-04-25 10:15:33 -04:00
|
|
|
def update_branches
|
|
|
|
@target_project = selected_target_project
|
2013-06-08 11:51:18 -04:00
|
|
|
@target_branches = @target_project.repository.branch_names
|
2014-01-23 03:08:26 -05:00
|
|
|
|
2016-03-29 07:43:33 -04:00
|
|
|
render layout: false
|
2013-04-25 10:15:33 -04:00
|
|
|
end
|
|
|
|
|
2012-12-10 22:14:05 -05:00
|
|
|
def ci_status
|
2016-06-02 10:19:18 -04:00
|
|
|
pipeline = @merge_request.pipeline
|
|
|
|
if pipeline
|
|
|
|
status = pipeline.status
|
|
|
|
coverage = pipeline.try(:coverage)
|
2016-05-25 04:59:11 -04:00
|
|
|
|
2016-07-14 10:58:05 -04:00
|
|
|
status = "success_with_warnings" if pipeline.success? && pipeline.has_warnings?
|
2016-07-12 13:05:48 -04:00
|
|
|
|
2016-05-25 04:59:11 -04:00
|
|
|
status ||= "preparing"
|
2016-01-25 16:20:24 -05:00
|
|
|
else
|
|
|
|
ci_service = @merge_request.source_project.ci_service
|
2016-06-20 12:48:04 -04:00
|
|
|
status = ci_service.commit_status(merge_request.diff_head_sha, merge_request.source_branch) if ci_service
|
2014-10-02 11:17:47 -04:00
|
|
|
|
2016-01-25 16:20:24 -05:00
|
|
|
if ci_service.respond_to?(:commit_coverage)
|
2016-06-20 12:48:04 -04:00
|
|
|
coverage = ci_service.commit_coverage(merge_request.diff_head_sha, merge_request.source_branch)
|
2016-01-25 16:20:24 -05:00
|
|
|
end
|
2014-10-02 11:17:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
response = {
|
2016-03-16 10:52:56 -04:00
|
|
|
title: merge_request.title,
|
2016-06-20 12:48:04 -04:00
|
|
|
sha: merge_request.diff_head_commit.short_id,
|
2014-10-02 11:17:47 -04:00
|
|
|
status: status,
|
|
|
|
coverage: coverage
|
|
|
|
}
|
2012-12-10 22:14:05 -05:00
|
|
|
|
|
|
|
render json: response
|
|
|
|
end
|
|
|
|
|
2011-11-28 02:39:43 -05:00
|
|
|
protected
|
|
|
|
|
2013-04-25 10:15:33 -04:00
|
|
|
def selected_target_project
|
2014-01-31 06:24:38 -05:00
|
|
|
if @project.id.to_s == params[:target_project_id] || @project.forked_project_link.nil?
|
|
|
|
@project
|
|
|
|
else
|
|
|
|
@project.forked_project_link.forked_from_project
|
|
|
|
end
|
2013-04-25 10:15:33 -04:00
|
|
|
end
|
|
|
|
|
2011-11-28 02:39:43 -05:00
|
|
|
def merge_request
|
2016-08-12 21:17:57 -04:00
|
|
|
@issuable = @merge_request ||= @project.merge_requests.find_by!(iid: params[:id])
|
2011-11-28 02:39:43 -05:00
|
|
|
end
|
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
|
|
|
|
2015-06-26 10:44:21 -04:00
|
|
|
def authorize_update_merge_request!
|
2015-06-26 09:55:56 -04:00
|
|
|
return render_404 unless can?(current_user, :update_merge_request, @merge_request)
|
2011-12-15 16:57:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_admin_merge_request!
|
2012-02-21 17:31:18 -05:00
|
|
|
return render_404 unless can?(current_user, :admin_merge_request, @merge_request)
|
2011-12-15 16:57:46 -05:00
|
|
|
end
|
2012-02-06 12:40:32 -05:00
|
|
|
|
2016-08-10 23:36:58 -04:00
|
|
|
def authorize_can_resolve_conflicts!
|
|
|
|
return render_404 unless @merge_request.conflicts_can_be_resolved_by?(current_user)
|
|
|
|
end
|
|
|
|
|
2012-02-06 12:40:32 -05:00
|
|
|
def module_enabled
|
|
|
|
return render_404 unless @project.merge_requests_enabled
|
|
|
|
end
|
2012-06-29 14:55:22 -04:00
|
|
|
|
|
|
|
def validates_merge_request
|
2013-12-12 04:34:42 -05:00
|
|
|
# If source project was removed (Ex. mr from fork to origin)
|
|
|
|
return invalid_mr unless @merge_request.source_project
|
|
|
|
|
2013-07-31 12:31:34 -04:00
|
|
|
# Show git not found page
|
|
|
|
# if there is no saved commits between source & target branch
|
|
|
|
if @merge_request.commits.blank?
|
2013-12-12 04:34:42 -05:00
|
|
|
# and if target branch doesn't exist
|
|
|
|
return invalid_mr unless @merge_request.target_branch_exists?
|
2013-07-31 12:31:34 -04:00
|
|
|
|
2013-12-12 04:34:42 -05:00
|
|
|
# or if source branch doesn't exist
|
|
|
|
return invalid_mr unless @merge_request.source_branch_exists?
|
2013-07-31 12:31:34 -04:00
|
|
|
end
|
2012-06-29 14:55:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def define_show_vars
|
2016-07-07 04:32:01 -04:00
|
|
|
@noteable = @merge_request
|
|
|
|
@commits_count = @merge_request.commits.count
|
|
|
|
|
|
|
|
@pipeline = @merge_request.pipeline
|
2016-08-11 09:22:35 -04:00
|
|
|
@statuses = @pipeline.statuses.relevant if @pipeline
|
2016-07-07 04:32:01 -04:00
|
|
|
|
|
|
|
if @merge_request.locked_long_ago?
|
|
|
|
@merge_request.unlock_mr
|
|
|
|
@merge_request.close
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-12 08:29:26 -04:00
|
|
|
# Discussion tab data is rendered on html responses of actions
|
|
|
|
# :show, :diff, :commits, :builds. but not when request the data through AJAX
|
|
|
|
def define_discussion_vars
|
2012-06-29 14:55:22 -04:00
|
|
|
# Build a note object for comment form
|
2016-07-26 00:43:47 -04:00
|
|
|
@note = @project.notes.new(noteable: @merge_request)
|
2016-06-21 07:35:09 -04:00
|
|
|
|
2016-07-26 00:43:47 -04:00
|
|
|
@discussions = @merge_request.discussions
|
2016-06-21 07:35:09 -04:00
|
|
|
|
2016-08-01 10:55:51 -04:00
|
|
|
preload_noteable_for_regular_notes(@discussions.flat_map(&:notes))
|
|
|
|
|
2016-07-07 04:32:01 -04:00
|
|
|
# This is not executed lazily
|
2016-06-21 07:35:09 -04:00
|
|
|
@notes = Banzai::NoteRenderer.render(
|
2016-07-20 18:18:18 -04:00
|
|
|
@discussions.flat_map(&:notes),
|
2016-06-21 07:35:09 -04:00
|
|
|
@project,
|
|
|
|
current_user,
|
|
|
|
@path,
|
|
|
|
@project_wiki,
|
|
|
|
@ref
|
|
|
|
)
|
2016-07-20 00:52:31 -04:00
|
|
|
|
2016-07-25 09:21:55 -04:00
|
|
|
preload_max_access_for_authors(@notes, @project)
|
2013-02-27 13:20:31 -05:00
|
|
|
end
|
|
|
|
|
2015-12-09 03:59:19 -05:00
|
|
|
def define_widget_vars
|
2016-06-07 07:19:15 -04:00
|
|
|
@pipeline = @merge_request.pipeline
|
|
|
|
@pipelines = [@pipeline].compact
|
2015-12-09 03:59:19 -05:00
|
|
|
end
|
|
|
|
|
2016-06-28 12:25:32 -04:00
|
|
|
def define_commit_vars
|
|
|
|
@commit = @merge_request.diff_head_commit
|
|
|
|
@base_commit = @merge_request.diff_base_commit || @merge_request.likely_diff_base_commit
|
|
|
|
end
|
|
|
|
|
|
|
|
def define_diff_comment_vars
|
|
|
|
@comments_target = {
|
|
|
|
noteable_type: 'MergeRequest',
|
|
|
|
noteable_id: @merge_request.id
|
|
|
|
}
|
|
|
|
|
2016-08-04 05:31:44 -04:00
|
|
|
@use_legacy_diff_notes = !@merge_request.has_complete_diff_refs?
|
2016-08-18 19:27:22 -04:00
|
|
|
@grouped_diff_discussions = @merge_request.notes.inc_relations_for_view.grouped_diff_discussions
|
2016-06-28 12:25:32 -04:00
|
|
|
|
|
|
|
Banzai::NoteRenderer.render(
|
2016-07-20 18:18:18 -04:00
|
|
|
@grouped_diff_discussions.values.flat_map(&:notes),
|
2016-06-28 12:25:32 -04:00
|
|
|
@project,
|
|
|
|
current_user,
|
|
|
|
@path,
|
|
|
|
@project_wiki,
|
|
|
|
@ref
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2013-11-27 03:17:29 -05:00
|
|
|
def invalid_mr
|
|
|
|
# Render special view for MR with removed source or target branch
|
|
|
|
render 'invalid'
|
|
|
|
end
|
|
|
|
|
2014-06-26 07:30:07 -04:00
|
|
|
def merge_request_params
|
2015-11-26 10:16:50 -05:00
|
|
|
params.require(:merge_request).permit(
|
2014-06-26 07:30:07 -04:00
|
|
|
:title, :assignee_id, :source_project_id, :source_branch,
|
|
|
|
:target_project_id, :target_branch, :milestone_id,
|
2016-02-12 15:41:31 -05:00
|
|
|
:state_event, :description, :task_num, :force_remove_source_branch,
|
2016-08-01 11:34:17 -04:00
|
|
|
:lock_version, label_ids: []
|
2014-06-26 07:30:07 -04:00
|
|
|
)
|
|
|
|
end
|
2015-09-21 10:25:59 -04:00
|
|
|
|
2015-11-02 11:27:38 -05:00
|
|
|
def merge_params
|
|
|
|
params.permit(:should_remove_source_branch, :commit_message)
|
|
|
|
end
|
|
|
|
|
2015-09-21 10:25:59 -04:00
|
|
|
# Make sure merge requests created before 8.0
|
|
|
|
# have head file in refs/merge-requests/
|
|
|
|
def ensure_ref_fetched
|
|
|
|
@merge_request.ensure_ref_fetched
|
|
|
|
end
|
2016-06-24 12:13:56 -04:00
|
|
|
|
|
|
|
def merge_when_build_succeeds_active?
|
|
|
|
params[:merge_when_build_succeeds].present? &&
|
|
|
|
@merge_request.pipeline && @merge_request.pipeline.active?
|
|
|
|
end
|
2016-06-28 12:25:32 -04:00
|
|
|
|
|
|
|
def build_merge_request
|
|
|
|
params[:merge_request] ||= ActionController::Parameters.new(source_project: @project)
|
|
|
|
@merge_request = MergeRequests::BuildService.new(project, current_user, merge_request_params).execute
|
|
|
|
end
|
2011-11-28 02:39:43 -05:00
|
|
|
end
|