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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
579bdd50
Commit
579bdd50
authored
Sep 12, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
e48177b7
8ace6442
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
2 deletions
+49
-2
app/services/merge_requests/create_from_issue_service.rb
app/services/merge_requests/create_from_issue_service.rb
+28
-2
changelogs/unreleased/50847-automatically-created-mr-uses-wrong-source-branch-when-branching-fr.yml
...created-mr-uses-wrong-source-branch-when-branching-fr.yml
+5
-0
spec/services/merge_requests/create_from_issue_service_spec.rb
...services/merge_requests/create_from_issue_service_spec.rb
+16
-0
No files found.
app/services/merge_requests/create_from_issue_service.rb
View file @
579bdd50
...
...
@@ -52,8 +52,26 @@ module MergeRequests
end
def
ref
return
@ref
if
target_project
.
repository
.
branch_exists?
(
@ref
)
if
valid_ref?
@ref
else
default_branch
end
end
def
valid_ref?
ref_is_branch?
||
ref_is_tag?
end
def
ref_is_branch?
target_project
.
repository
.
branch_exists?
(
@ref
)
end
def
ref_is_tag?
target_project
.
repository
.
tag_exists?
(
@ref
)
end
def
default_branch
target_project
.
default_branch
||
'master'
end
...
...
@@ -67,10 +85,18 @@ module MergeRequests
source_project_id:
target_project
.
id
,
source_branch:
branch_name
,
target_project_id:
target_project
.
id
,
target_branch:
ref
target_branch:
target_branch
}
end
def
target_branch
if
ref_is_branch?
@ref
else
default_branch
end
end
def
success
(
merge_request
)
super
().
merge
(
merge_request:
merge_request
)
end
...
...
changelogs/unreleased/50847-automatically-created-mr-uses-wrong-source-branch-when-branching-fr.yml
0 → 100644
View file @
579bdd50
---
title
:
Fix create MR from issue using a tag as ref
merge_request
:
32392
author
:
Jacopo Beschi @jacopo-beschi
type
:
fixed
spec/services/merge_requests/create_from_issue_service_spec.rb
View file @
579bdd50
...
...
@@ -112,6 +112,22 @@ describe MergeRequests::CreateFromIssueService do
expect
(
subject
[
:merge_request
].
target_branch
).
to
eq
(
'feature'
)
end
context
'when the ref is a tag'
do
subject
{
described_class
.
new
(
project
,
user
,
ref:
'v1.0.0'
,
**
service_params
).
execute
}
it
'sets the merge request source branch to the new issue branch'
do
expect
(
subject
[
:merge_request
].
source_branch
).
to
eq
(
issue
.
to_branch_name
)
end
it
'creates a merge request'
do
expect
{
subject
}.
to
change
(
target_project
.
merge_requests
,
:count
).
by
(
1
)
end
it
'sets the merge request target branch to the project default branch'
do
expect
(
subject
[
:merge_request
].
target_branch
).
to
eq
(
target_project
.
default_branch
)
end
end
context
'when ref branch does not exist'
do
subject
{
described_class
.
new
(
project
,
user
,
ref:
'no-such-branch'
,
**
service_params
).
execute
}
...
...
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