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
31409030
Commit
31409030
authored
Feb 15, 2017
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create compare object with default branch when target branch is missing
parent
608711c2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
18 deletions
+25
-18
app/services/merge_requests/build_service.rb
app/services/merge_requests/build_service.rb
+15
-11
changelogs/unreleased/issue_28051_2.yml
changelogs/unreleased/issue_28051_2.yml
+4
-0
spec/services/merge_requests/build_service_spec.rb
spec/services/merge_requests/build_service_spec.rb
+6
-7
No files found.
app/services/merge_requests/build_service.rb
View file @
31409030
...
@@ -2,18 +2,14 @@ module MergeRequests
...
@@ -2,18 +2,14 @@ module MergeRequests
class
BuildService
<
MergeRequests
::
BaseService
class
BuildService
<
MergeRequests
::
BaseService
def
execute
def
execute
self
.
merge_request
=
MergeRequest
.
new
(
params
)
self
.
merge_request
=
MergeRequest
.
new
(
params
)
merge_request
.
can_be_created
=
true
merge_request
.
compare_commits
=
[]
merge_request
.
compare_commits
=
[]
merge_request
.
source_project
=
find_source_project
merge_request
.
source_project
=
find_source_project
merge_request
.
target_project
=
find_target_project
merge_request
.
target_project
=
find_target_project
merge_request
.
target_branch
=
find_target_branch
merge_request
.
target_branch
=
find_target_branch
merge_request
.
can_be_created
=
branches_valid?
&&
source_branch_specified?
&&
target_branch_specified?
if
branches_specified?
&&
branches_valid?
compare_branches
if
branches_present?
compare_branches
assign_title_and_description
if
merge_request
.
can_be_created
assign_title_and_description
else
merge_request
.
can_be_created
=
false
end
merge_request
merge_request
end
end
...
@@ -37,11 +33,17 @@ module MergeRequests
...
@@ -37,11 +33,17 @@ module MergeRequests
target_branch
||
target_project
.
default_branch
target_branch
||
target_project
.
default_branch
end
end
def
branches_specified?
def
source_branch_specified?
params
[
:source_branch
]
&&
params
[
:target_branch
]
params
[
:source_branch
].
present?
end
def
target_branch_specified?
params
[
:target_branch
].
present?
end
end
def
branches_valid?
def
branches_valid?
return
false
unless
source_branch_specified?
||
target_branch_specified?
validate_branches
validate_branches
errors
.
blank?
errors
.
blank?
end
end
...
@@ -55,9 +57,11 @@ module MergeRequests
...
@@ -55,9 +57,11 @@ module MergeRequests
target_branch
target_branch
)
)
if
compare
merge_request
.
compare_commits
=
compare
.
commits
merge_request
.
compare_commits
=
compare
.
commits
merge_request
.
compare
=
compare
merge_request
.
compare
=
compare
end
end
end
def
validate_branches
def
validate_branches
add_error
(
'You must select source and target branch'
)
unless
branches_present?
add_error
(
'You must select source and target branch'
)
unless
branches_present?
...
...
changelogs/unreleased/issue_28051_2.yml
0 → 100644
View file @
31409030
---
title
:
Use default branch as target_branch when parameter is missing
merge_request
:
author
:
spec/services/merge_requests/build_service_spec.rb
View file @
31409030
...
@@ -44,15 +44,14 @@ describe MergeRequests::BuildService, services: true do
...
@@ -44,15 +44,14 @@ describe MergeRequests::BuildService, services: true do
end
end
end
end
context
'missing target branch'
do
context
'when target branch is missing'
do
let
(
:target_branch
)
{
''
}
let
(
:target_branch
)
{
nil
}
let
(
:commits
)
{
Commit
.
decorate
([
commit_1
],
project
)
}
it
'
forbids the merge request from being created
'
do
it
'
creates compare object with target branch as default branch
'
do
expect
(
merge_request
.
can_be_created
).
to
eq
(
false
)
expect
(
merge_request
.
can_be_created
).
to
eq
(
false
)
end
expect
(
merge_request
.
compare
).
to
be_present
expect
(
merge_request
.
target_branch
).
to
eq
(
project
.
default_branch
)
it
'adds an error message to the merge request'
do
expect
(
merge_request
.
errors
).
to
contain_exactly
(
'You must select source and target branch'
)
end
end
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