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
Tatuya Kamada
gitlab-ce
Commits
97ec0c05
Commit
97ec0c05
authored
Oct 04, 2016
by
Douglas Barbosa Alexandre
Committed by
Phil Hughes
Oct 06, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add service to create a new issue in a board list
parent
e7a4bbb0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
11 deletions
+67
-11
app/controllers/projects/boards/issues_controller.rb
app/controllers/projects/boards/issues_controller.rb
+18
-11
app/services/boards/issues/create_service.rb
app/services/boards/issues/create_service.rb
+16
-0
spec/services/boards/issues/create_service_spec.rb
spec/services/boards/issues/create_service_spec.rb
+33
-0
No files found.
app/controllers/projects/boards/issues_controller.rb
View file @
97ec0c05
...
...
@@ -10,23 +10,21 @@ module Projects
issues
=
issues
.
page
(
params
[
:page
])
render
json:
{
issues:
issues
.
as_json
(
only:
[
:iid
,
:title
,
:confidential
],
include:
{
assignee:
{
only:
[
:id
,
:name
,
:username
],
methods:
[
:avatar_url
]
},
labels:
{
only:
[
:id
,
:title
,
:description
,
:color
,
:priority
],
methods:
[
:text_color
]
}
}),
issues:
serialize_as_json
(
issues
),
size:
issues
.
total_count
}
end
def
create
list
=
project
.
board
.
lists
.
find
(
params
[
:list_id
])
service
=
::
Boards
::
Issues
::
CreateService
.
new
(
project
,
current_user
,
issue_params
)
issue
=
service
.
execute
(
list
)
issue
=
Issues
::
CreateService
.
new
(
project
,
current_user
,
issue_params
.
merge
(
request:
request
)).
execute
issue
.
labels
<<
list
.
label
if
list
.
label
render
json:
issue
.
to_json
if
issue
.
valid?
render
json:
serialize_as_json
(
issue
)
else
render
json:
issue
.
errors
,
status: :unprocessable_entity
end
end
def
update
...
...
@@ -70,7 +68,16 @@ module Projects
end
def
issue_params
params
.
require
(
:issue
).
permit
(
:title
)
params
.
require
(
:issue
).
permit
(
:title
).
merge
(
request:
request
)
end
def
serialize_as_json
(
resource
)
resource
.
as_json
(
only:
[
:iid
,
:title
,
:confidential
],
include:
{
assignee:
{
only:
[
:id
,
:name
,
:username
],
methods:
[
:avatar_url
]
},
labels:
{
only:
[
:id
,
:title
,
:description
,
:color
,
:priority
],
methods:
[
:text_color
]
}
})
end
end
end
...
...
app/services/boards/issues/create_service.rb
0 → 100644
View file @
97ec0c05
module
Boards
module
Issues
class
CreateService
<
Boards
::
BaseService
def
execute
(
list
)
params
.
merge!
(
label_ids:
[
list
.
label_id
])
create_issue
end
private
def
create_issue
::
Issues
::
CreateService
.
new
(
project
,
current_user
,
params
).
execute
end
end
end
end
spec/services/boards/issues/create_service_spec.rb
0 → 100644
View file @
97ec0c05
require
'spec_helper'
describe
Boards
::
Issues
::
CreateService
,
services:
true
do
describe
'#execute'
do
let
(
:project
)
{
create
(
:project_with_board
)
}
let
(
:board
)
{
project
.
board
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:label
)
{
create
(
:label
,
project:
project
,
name:
'in-progress'
)
}
let!
(
:list
)
{
create
(
:list
,
board:
board
,
label:
label
,
position:
0
)
}
subject
(
:service
)
{
described_class
.
new
(
project
,
user
,
title:
'New issue'
)
}
before
do
project
.
team
<<
[
user
,
:developer
]
end
it
'delegates the create proceedings to Issues::CreateService'
do
expect_any_instance_of
(
Issues
::
CreateService
).
to
receive
(
:execute
).
once
service
.
execute
(
list
)
end
it
'creates a new issue'
do
expect
{
service
.
execute
(
list
)
}.
to
change
(
project
.
issues
,
:count
).
by
(
1
)
end
it
'adds the label of the list to the issue'
do
issue
=
service
.
execute
(
list
)
expect
(
issue
.
labels
).
to
eq
[
label
]
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