Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
4d801a70
Commit
4d801a70
authored
Oct 12, 2018
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inline the new checks into normal update error handling
parent
b96dbc67
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
22 deletions
+30
-22
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+8
-13
app/models/merge_request.rb
app/models/merge_request.rb
+17
-6
spec/controllers/projects/merge_requests_controller_spec.rb
spec/controllers/projects/merge_requests_controller_spec.rb
+5
-3
No files found.
app/controllers/projects/merge_requests_controller.rb
View file @
4d801a70
...
...
@@ -7,7 +7,6 @@ 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
]
...
...
@@ -123,19 +122,21 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
respond_to
do
|
format
|
format
.
html
do
check_branch_conflict
if
@merge_request
.
valid?
redirect_to
([
@merge_request
.
target_project
.
namespace
.
becomes
(
Namespace
),
@merge_request
.
target_project
,
@merge_request
])
else
if
@merge_request
.
errors
.
present?
define_edit_vars
render
:edit
else
redirect_to
project_merge_request_path
(
@merge_request
.
target_project
,
@merge_request
)
end
end
format
.
json
do
render
json:
serializer
.
represent
(
@merge_request
,
serializer:
'basic'
)
if
merge_request
.
errors
.
present?
render
json:
@merge_request
.
errors
,
status: :bad_request
else
render
json:
serializer
.
represent
(
@merge_request
,
serializer:
'basic'
)
end
end
end
rescue
ActiveRecord
::
StaleObjectError
...
...
@@ -258,12 +259,6 @@ 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
...
...
app/models/merge_request.rb
View file @
4d801a70
...
...
@@ -539,15 +539,26 @@ class MergeRequest < ActiveRecord::Base
def
validate_branches
if
target_project
==
source_project
&&
target_branch
==
source_branch
errors
.
add
:branch_conflict
,
"You can not use same project/branch for source and target"
errors
.
add
:branch_conflict
,
"You can't use same project/branch for source and target"
return
end
if
opened?
similar_mrs
=
self
.
target_project
.
merge_requests
.
where
(
source_branch:
source_branch
,
target_branch:
target_branch
,
source_project_id:
source_project
.
try
(
:id
)).
opened
similar_mrs
=
similar_mrs
.
where
(
'id not in (?)'
,
self
.
id
)
if
self
.
id
if
similar_mrs
.
any?
errors
.
add
:validate_branches
,
"Another open Merge Request already exists for this source branch: !
#{
similar_mrs
.
first
.
id
}
"
similar_mrs
=
target_project
.
merge_requests
.
where
(
source_branch:
source_branch
,
target_branch:
target_branch
)
.
where
(
source_project_id:
source_project
&
.
id
)
.
opened
similar_mrs
=
similar_mrs
.
where
.
not
(
id:
id
)
if
persisted?
conflict
=
similar_mrs
.
first
if
conflict
.
present?
errors
.
add
(
:validate_branches
,
"Another open merge request already exists for this source branch:
#{
conflict
.
to_reference
}
"
)
end
end
end
...
...
spec/controllers/projects/merge_requests_controller_spec.rb
View file @
4d801a70
...
...
@@ -291,14 +291,16 @@ describe Projects::MergeRequestsController do
it_behaves_like
'update invalid issuable'
,
MergeRequest
end
context
't
here are t
wo merge requests with the same source branch'
do
it
"does not allow to reopen a closed merge request if another one is open"
do
context
'two merge requests with the same source branch'
do
it
'does not allow a closed merge request to be reopened if another one is open'
do
merge_request
.
close!
create
(
:merge_request
,
source_project:
merge_request
.
source_project
,
source_branch:
merge_request
.
source_branch
)
update_merge_request
(
state_event:
'reopen'
)
expect
(
controller
).
to
set_flash
[
:alert
].
to
(
/Another open Merge Request already exists for this source branch/
)
errors
=
assigns
[
:merge_request
].
errors
expect
(
errors
[
:validate_branches
]).
to
include
(
/Another open merge request already exists for this source branch/
)
expect
(
merge_request
.
reload
).
to
be_closed
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment