Commit 4a31c677 authored by Akos Gyimesi's avatar Akos Gyimesi Committed by Nick Thomas

Link to conflicting MR in reopening error message

Also, the error message became shorter.
parent 5fd5dad4
......@@ -7,6 +7,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
include RendersCommits
include ToggleAwardEmoji
include IssuableCollections
include MarkupHelper
skip_before_action :merge_request, only: [:index, :bulk_update]
before_action :whitelist_query_limiting, only: [:assign_related_issues, :update]
......@@ -122,9 +123,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
respond_to do |format|
format.html do
if merge_request_params[:state_event] && @merge_request.errors.any?
flash[:alert] = @merge_request.errors.values.flatten.to_sentence
end
check_branch_conflict
if @merge_request.valid?
redirect_to([@merge_request.target_project.namespace.becomes(Namespace), @merge_request.target_project, @merge_request])
......@@ -259,6 +258,12 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
@merge_request.check_if_can_be_merged
end
def check_branch_conflict
if @merge_request.errors[:validate_branches]
flash[:alert] = markdown(@merge_request.errors[:validate_branches].to_sentence, pipeline: :single_line)
end
end
def merge!
# Disable the CI check if merge_when_pipeline_succeeds is enabled since we have
# to wait until CI completes to know
......
......@@ -547,7 +547,7 @@ class MergeRequest < ActiveRecord::Base
similar_mrs = similar_mrs.where('id not in (?)', self.id) if self.id
if similar_mrs.any?
errors.add :validate_branches,
"Cannot open this Merge Request because another open Merge Request already exists for this source branch: #{similar_mrs.first.title}"
"Another open Merge Request already exists for this source branch: !#{similar_mrs.first.id}"
end
end
end
......
......@@ -298,7 +298,7 @@ describe Projects::MergeRequestsController do
update_merge_request(state_event: 'reopen')
expect(controller).to set_flash[:alert].to(/another open Merge Request already exists for this source branch/)
expect(controller).to set_flash[:alert].to(/Another open Merge Request already exists for this source branch/)
expect(merge_request.reload).to be_closed
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment