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
Léo-Paul Géneau
gitlab-ce
Commits
422a01fc
Commit
422a01fc
authored
Feb 15, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create a pending task when an issue is assigned to someone
parent
1e0053f2
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
141 additions
and
2 deletions
+141
-2
app/services/base_service.rb
app/services/base_service.rb
+4
-0
app/services/issues/create_service.rb
app/services/issues/create_service.rb
+1
-0
app/services/issues/update_service.rb
app/services/issues/update_service.rb
+1
-0
app/services/task_service.rb
app/services/task_service.rb
+43
-0
spec/services/issues/create_service_spec.rb
spec/services/issues/create_service_spec.rb
+20
-2
spec/services/issues/update_service_spec.rb
spec/services/issues/update_service_spec.rb
+13
-0
spec/services/task_service_spec.rb
spec/services/task_service_spec.rb
+59
-0
No files found.
app/services/base_service.rb
View file @
422a01fc
...
...
@@ -23,6 +23,10 @@ class BaseService
EventCreateService
.
new
end
def
task_service
TaskService
.
new
end
def
log_info
(
message
)
Gitlab
::
AppLogger
.
info
message
end
...
...
app/services/issues/create_service.rb
View file @
422a01fc
...
...
@@ -9,6 +9,7 @@ module Issues
if
issue
.
save
issue
.
update_attributes
(
label_ids:
label_params
)
notification_service
.
new_issue
(
issue
,
current_user
)
task_service
.
new_issue
(
issue
,
current_user
)
event_service
.
open_issue
(
issue
,
current_user
)
issue
.
create_cross_references!
(
current_user
)
execute_hooks
(
issue
,
'open'
)
...
...
app/services/issues/update_service.rb
View file @
422a01fc
...
...
@@ -12,6 +12,7 @@ module Issues
if
issue
.
previous_changes
.
include?
(
'assignee_id'
)
create_assignee_note
(
issue
)
notification_service
.
reassigned_issue
(
issue
,
current_user
)
task_service
.
reassigned_issue
(
issue
,
current_user
)
end
end
...
...
app/services/task_service.rb
0 → 100644
View file @
422a01fc
# TaskService class
#
# Used for creating tasks on task queue after certain user action
#
# Ex.
# TaskService.new.new_issue(issue, current_user)
#
class
TaskService
# When create an issue we should:
#
# * creates a pending task for assignee if issue is assigned
#
def
new_issue
(
issue
,
current_user
)
if
issue
.
is_assigned?
create_task
(
issue
.
project
,
issue
,
current_user
,
issue
.
assignee
,
Task
::
ASSIGNED
)
end
end
# When we reassign an issue we should:
#
# * creates a pending task for new assignee if issue is assigned
#
def
reassigned_issue
(
issue
,
current_user
)
if
issue
.
is_assigned?
create_task
(
issue
.
project
,
issue
,
current_user
,
issue
.
assignee
,
Task
::
ASSIGNED
)
end
end
private
def
create_task
(
project
,
target
,
author
,
user
,
action
)
attributes
=
{
project:
project
,
user_id:
user
.
id
,
author_id:
author
.
id
,
target_id:
target
.
id
,
target_type:
target
.
class
.
name
,
action:
action
}
Task
.
create
(
attributes
)
end
end
spec/services/issues/create_service_spec.rb
View file @
422a01fc
...
...
@@ -3,14 +3,18 @@ require 'spec_helper'
describe
Issues
::
CreateService
,
services:
true
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:assignee
)
{
create
(
:user
)
}
describe
:execute
do
context
"valid params"
do
context
'valid params'
do
before
do
project
.
team
<<
[
user
,
:master
]
project
.
team
<<
[
assignee
,
:master
]
opts
=
{
title:
'Awesome issue'
,
description:
'please fix'
description:
'please fix'
,
assignee:
assignee
}
@issue
=
Issues
::
CreateService
.
new
(
project
,
user
,
opts
).
execute
...
...
@@ -18,6 +22,20 @@ describe Issues::CreateService, services: true do
it
{
expect
(
@issue
).
to
be_valid
}
it
{
expect
(
@issue
.
title
).
to
eq
(
'Awesome issue'
)
}
it
{
expect
(
@issue
.
assignee
).
to
eq
assignee
}
it
'creates a pending task for new assignee'
do
attributes
=
{
project:
project
,
author:
user
,
user:
assignee
,
target:
@issue
,
action:
Task
::
ASSIGNED
,
state: :pending
}
expect
(
Task
.
where
(
attributes
).
count
).
to
eq
1
end
end
end
end
spec/services/issues/update_service_spec.rb
View file @
422a01fc
...
...
@@ -78,6 +78,19 @@ describe Issues::UpdateService, services: true do
expect
(
note
).
not_to
be_nil
expect
(
note
.
note
).
to
eq
'Title changed from **Old title** to **New title**'
end
it
'creates a pending task if being reassigned'
do
attributes
=
{
project:
project
,
author:
user
,
user:
user2
,
target:
issue
,
action:
Task
::
ASSIGNED
,
state: :pending
}
expect
(
Task
.
where
(
attributes
).
count
).
to
eq
1
end
end
context
'when Issue has tasks'
do
...
...
spec/services/task_service_spec.rb
0 → 100644
View file @
422a01fc
require
'spec_helper'
describe
TaskService
,
services:
true
do
let
(
:service
)
{
described_class
.
new
}
describe
'Issues'
do
let
(
:author
)
{
create
(
:user
)
}
let
(
:john_doe
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:empty_project
,
:public
)
}
let
(
:assigned_issue
)
{
create
(
:issue
,
project:
project
,
assignee:
john_doe
)
}
let
(
:unassigned_issue
)
{
create
(
:issue
,
project:
project
,
assignee:
nil
)
}
before
do
project
.
team
<<
[
author
,
:developer
]
project
.
team
<<
[
john_doe
,
:developer
]
end
describe
'#new_issue'
do
it
'creates a pending task if assigned'
do
service
.
new_issue
(
assigned_issue
,
author
)
is_expected_to_create_pending_task
(
user:
john_doe
,
target:
assigned_issue
,
action:
Task
::
ASSIGNED
)
end
it
'does not create a task if unassigned'
do
is_expected_to_not_create_task
{
service
.
new_issue
(
unassigned_issue
,
author
)
}
end
end
describe
'#reassigned_issue'
do
it
'creates a pending task for new assignee'
do
unassigned_issue
.
update_attribute
(
:assignee
,
john_doe
)
service
.
reassigned_issue
(
unassigned_issue
,
author
)
is_expected_to_create_pending_task
(
user:
john_doe
,
target:
unassigned_issue
,
action:
Task
::
ASSIGNED
)
end
it
'does not create a task if unassigned'
do
assigned_issue
.
update_attribute
(
:assignee
,
nil
)
is_expected_to_not_create_task
{
service
.
reassigned_issue
(
assigned_issue
,
author
)
}
end
end
end
def
is_expected_to_create_pending_task
(
attributes
=
{})
attributes
.
reverse_merge!
(
project:
project
,
author:
author
,
state: :pending
)
expect
(
Task
.
where
(
attributes
).
count
).
to
eq
1
end
def
is_expected_to_not_create_task
expect
{
yield
}.
not_to
change
(
Task
,
:count
)
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