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
d368b2d2
Commit
d368b2d2
authored
Aug 17, 2017
by
haseeb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved merge parms to service
parent
59d7ffad
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
33 deletions
+17
-33
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+1
-11
app/services/merge_requests/create_from_issue_service.rb
app/services/merge_requests/create_from_issue_service.rb
+4
-1
spec/services/merge_requests/create_from_issue_service_spec.rb
...services/merge_requests/create_from_issue_service_spec.rb
+12
-21
No files found.
app/controllers/projects/issues_controller.rb
View file @
d368b2d2
...
@@ -212,7 +212,7 @@ class Projects::IssuesController < Projects::ApplicationController
...
@@ -212,7 +212,7 @@ class Projects::IssuesController < Projects::ApplicationController
end
end
def
create_merge_request
def
create_merge_request
result
=
::
MergeRequests
::
CreateFromIssueService
.
new
(
project
,
current_user
,
merge_request_params
).
execute
result
=
::
MergeRequests
::
CreateFromIssueService
.
new
(
project
,
current_user
,
issue_iid:
issue
.
iid
).
execute
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
render
json:
MergeRequestCreateSerializer
.
new
.
represent
(
result
[
:merge_request
])
render
json:
MergeRequestCreateSerializer
.
new
.
represent
(
result
[
:merge_request
])
...
@@ -287,14 +287,4 @@ class Projects::IssuesController < Projects::ApplicationController
...
@@ -287,14 +287,4 @@ class Projects::IssuesController < Projects::ApplicationController
redirect_to
new_user_session_path
,
notice:
notice
redirect_to
new_user_session_path
,
notice:
notice
end
end
private
def
merge_request_params
{
issue_iid:
issue
.
iid
,
label_ids:
issue
.
label_ids
,
milestone_id:
issue
.
milestone_id
}
end
end
end
app/services/merge_requests/create_from_issue_service.rb
View file @
d368b2d2
...
@@ -3,6 +3,8 @@ module MergeRequests
...
@@ -3,6 +3,8 @@ module MergeRequests
def
execute
def
execute
return
error
(
'Invalid issue iid'
)
unless
issue_iid
.
present?
&&
issue
.
present?
return
error
(
'Invalid issue iid'
)
unless
issue_iid
.
present?
&&
issue
.
present?
params
[
:label_ids
]
=
issue
.
label_ids
if
issue
.
label_ids
.
any?
result
=
CreateBranchService
.
new
(
project
,
current_user
).
execute
(
branch_name
,
ref
)
result
=
CreateBranchService
.
new
(
project
,
current_user
).
execute
(
branch_name
,
ref
)
return
result
if
result
[
:status
]
==
:error
return
result
if
result
[
:status
]
==
:error
...
@@ -43,7 +45,8 @@ module MergeRequests
...
@@ -43,7 +45,8 @@ module MergeRequests
{
{
source_project_id:
project
.
id
,
source_project_id:
project
.
id
,
source_branch:
branch_name
,
source_branch:
branch_name
,
target_project_id:
project
.
id
target_project_id:
project
.
id
,
milestone_id:
issue
.
milestone_id
}
}
end
end
...
...
spec/services/merge_requests/create_from_issue_service_spec.rb
View file @
d368b2d2
...
@@ -3,22 +3,11 @@ require 'spec_helper'
...
@@ -3,22 +3,11 @@ require 'spec_helper'
describe
MergeRequests
::
CreateFromIssueService
do
describe
MergeRequests
::
CreateFromIssueService
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:
issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:
label_ids
)
{
create_pair
(
:label
,
project:
project
).
map
(
&
:id
)
}
let
(
:milestone
)
{
create
(
:milestone
,
project:
project
)
}
let
(
:milestone
_id
)
{
create
(
:milestone
,
project:
project
).
id
}
let
(
:
labels
)
{
create_pair
(
:label
,
project:
project
)
}
let
(
:
issue
)
{
create
(
:issue
,
project:
project
,
milestone_id:
milestone_id
)
}
subject
(
:service
)
{
described_class
.
new
(
project
,
user
,
issue_iid:
issue
.
iid
)
}
subject
(
:service
)
{
described_class
.
new
(
project
,
user
,
issue_iid:
issue
.
iid
)
}
subject
(
:service2
)
do
described_class
.
new
(
project
,
user
,
{
issue_iid:
issue
.
iid
,
milestone_id:
milestone
.
id
,
label_ids:
labels
.
map
(
&
:id
)
}
)
end
before
do
before
do
project
.
add_developer
(
user
)
project
.
add_developer
(
user
)
...
@@ -38,16 +27,18 @@ describe MergeRequests::CreateFromIssueService do
...
@@ -38,16 +27,18 @@ describe MergeRequests::CreateFromIssueService do
described_class
.
new
(
project
,
user
,
issue_iid:
-
1
).
execute
described_class
.
new
(
project
,
user
,
issue_iid:
-
1
).
execute
end
end
it
"can inherit labels"
do
it
"inherits labels"
do
result
=
service2
.
execute
issue
.
assign_attributes
(
label_ids:
label_ids
)
result
=
service
.
execute
expect
(
result
[
:merge_request
].
label_ids
).
to
eq
(
label
s
.
map
(
&
:id
)
)
expect
(
result
[
:merge_request
].
label_ids
).
to
eq
(
label
_ids
)
end
end
it
"
can inherit
milestones"
do
it
"
inherits
milestones"
do
result
=
service
2
.
execute
result
=
service
.
execute
expect
(
result
[
:merge_request
].
milestone_id
).
to
eq
(
milestone
.
id
)
expect
(
result
[
:merge_request
].
milestone_id
).
to
eq
(
milestone
_
id
)
end
end
it
'delegates the branch creation to CreateBranchService'
do
it
'delegates the branch creation to CreateBranchService'
do
...
...
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