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
09454b70
Commit
09454b70
authored
Jun 19, 2019
by
Patrick Bajao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support creating an MR on a fork from an issue
parent
3fe7c990
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
222 additions
and
93 deletions
+222
-93
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+1
-0
app/services/merge_requests/create_from_issue_service.rb
app/services/merge_requests/create_from_issue_service.rb
+27
-11
spec/services/merge_requests/create_from_issue_service_spec.rb
...services/merge_requests/create_from_issue_service_spec.rb
+194
-82
No files found.
app/controllers/projects/issues_controller.rb
View file @
09454b70
...
...
@@ -172,6 +172,7 @@ class Projects::IssuesController < Projects::ApplicationController
def
create_merge_request
create_params
=
params
.
slice
(
:branch_name
,
:ref
).
merge
(
issue_iid:
issue
.
iid
)
create_params
[
:target_project_id
]
=
params
[
:target_project_id
]
if
Feature
.
enabled?
(
:create_confidential_merge_request
,
@project
)
result
=
::
MergeRequests
::
CreateFromIssueService
.
new
(
project
,
current_user
,
create_params
).
execute
if
result
[
:status
]
==
:success
...
...
app/services/merge_requests/create_from_issue_service.rb
View file @
09454b70
...
...
@@ -6,27 +6,30 @@ module MergeRequests
# branch - the name of new branch
# ref - the source of new branch.
@branch_name
=
params
[
:branch_name
]
@issue_iid
=
params
[
:issue_iid
]
@ref
=
params
[
:ref
]
@branch_name
=
params
[
:branch_name
]
@issue_iid
=
params
[
:issue_iid
]
@ref
=
params
[
:ref
]
@target_project_id
=
params
[
:target_project_id
]
super
(
project
,
user
)
end
def
execute
return
error
(
'Project not found'
)
if
target_project
.
blank?
return
error
(
'Not allowed to create merge request'
)
unless
can_create_merge_request?
return
error
(
'Invalid issue iid'
)
unless
@issue_iid
.
present?
&&
issue
.
present?
result
=
CreateBranchService
.
new
(
project
,
current_user
).
execute
(
branch_name
,
ref
)
result
=
CreateBranchService
.
new
(
target_
project
,
current_user
).
execute
(
branch_name
,
ref
)
return
result
if
result
[
:status
]
==
:error
new_merge_request
=
create
(
merge_request
)
if
new_merge_request
.
valid?
SystemNoteService
.
new_merge_request
(
issue
,
project
,
current_user
,
new_merge_request
)
SystemNoteService
.
new_merge_request
(
issue
,
target_
project
,
current_user
,
new_merge_request
)
success
(
new_merge_request
)
else
SystemNoteService
.
new_issue_branch
(
issue
,
project
,
current_user
,
branch_name
)
SystemNoteService
.
new_issue_branch
(
issue
,
target_
project
,
current_user
,
branch_name
)
error
(
new_merge_request
.
errors
)
end
...
...
@@ -34,6 +37,10 @@ module MergeRequests
private
def
can_create_merge_request?
can?
(
current_user
,
:create_merge_request_from
,
target_project
)
end
# rubocop: disable CodeReuse/ActiveRecord
def
issue
@issue
||=
IssuesFinder
.
new
(
current_user
,
project_id:
project
.
id
).
find_by
(
iid:
@issue_iid
)
...
...
@@ -45,21 +52,21 @@ module MergeRequests
end
def
ref
return
@ref
if
project
.
repository
.
branch_exists?
(
@ref
)
return
@ref
if
target_
project
.
repository
.
branch_exists?
(
@ref
)
project
.
default_branch
||
'master'
target_
project
.
default_branch
||
'master'
end
def
merge_request
MergeRequests
::
BuildService
.
new
(
project
,
current_user
,
merge_request_params
).
execute
MergeRequests
::
BuildService
.
new
(
target_
project
,
current_user
,
merge_request_params
).
execute
end
def
merge_request_params
{
issue_iid:
@issue_iid
,
source_project_id:
project
.
id
,
source_project_id:
target_
project
.
id
,
source_branch:
branch_name
,
target_project_id:
project
.
id
,
target_project_id:
target_
project
.
id
,
target_branch:
ref
}
end
...
...
@@ -67,5 +74,14 @@ module MergeRequests
def
success
(
merge_request
)
super
().
merge
(
merge_request:
merge_request
)
end
def
target_project
@target_project
||=
if
@target_project_id
.
present?
project
.
forks
.
find_by_id
(
@target_project_id
)
else
project
end
end
end
end
spec/services/merge_requests/create_from_issue_service_spec.rb
View file @
09454b70
This diff is collapsed.
Click to expand it.
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