debian-mirror-gitlab/app/controllers/projects/merge_requests/conflicts_controller.rb

75 lines
2.3 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
class Projects::MergeRequests::ConflictsController < Projects::MergeRequests::ApplicationController
include IssuableActions
before_action :authorize_can_resolve_conflicts!
def show
respond_to do |format|
format.html do
2019-02-15 15:39:39 +05:30
@issuable_sidebar = serializer.represent(@merge_request, serializer: 'sidebar')
2017-09-10 17:25:29 +05:30
end
format.json do
if @conflicts_list.can_be_resolved_in_ui?
render json: @conflicts_list
elsif @merge_request.can_be_merged?
render json: {
2019-05-30 16:15:17 +05:30
message: 'The merge conflicts for this merge request have already been resolved. Please return to the merge request.',
2017-09-10 17:25:29 +05:30
type: 'error'
}
else
render json: {
2019-05-30 16:15:17 +05:30
message: 'The merge conflicts for this merge request cannot be resolved through GitLab. Please try to resolve them locally.',
2017-09-10 17:25:29 +05:30
type: 'error'
}
end
end
end
end
def conflict_for_path
return render_404 unless @conflicts_list.can_be_resolved_in_ui?
file = @conflicts_list.file_for_path(params[:old_path], params[:new_path])
return render_404 unless file
render json: file, full_content: true
end
def resolve_conflicts
return render_404 unless @conflicts_list.can_be_resolved_in_ui?
if @merge_request.can_be_merged?
2019-05-30 16:15:17 +05:30
render status: :bad_request, json: { message: 'The merge conflicts for this merge request have already been resolved.' }
2017-09-10 17:25:29 +05:30
return
end
begin
::MergeRequests::Conflicts::ResolveService
.new(merge_request)
.execute(current_user, params)
2019-05-30 16:15:17 +05:30
flash[:notice] = 'All merge conflicts were resolved. The merge request can now be merged.'
2017-09-10 17:25:29 +05:30
render json: { redirect_to: project_merge_request_url(@project, @merge_request, resolved_conflicts: true) }
2018-03-17 18:26:18 +05:30
rescue Gitlab::Git::Conflict::Resolver::ResolutionError => e
2017-09-10 17:25:29 +05:30
render status: :bad_request, json: { message: e.message }
end
end
2019-02-15 15:39:39 +05:30
private
2017-09-10 17:25:29 +05:30
def authorize_can_resolve_conflicts!
@conflicts_list = ::MergeRequests::Conflicts::ListService.new(@merge_request)
return render_404 unless @conflicts_list.can_be_resolved_by?(current_user)
end
2019-02-15 15:39:39 +05:30
def serializer
MergeRequestSerializer.new(current_user: current_user, project: project)
end
2017-09-10 17:25:29 +05:30
end