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
d372ae68
Commit
d372ae68
authored
Jun 05, 2020
by
allison.browne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add method to assign alerts
parent
7ac786bc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
43 deletions
+64
-43
app/services/todo_service.rb
app/services/todo_service.rb
+12
-4
spec/services/todo_service_spec.rb
spec/services/todo_service_spec.rb
+52
-39
No files found.
app/services/todo_service.rb
View file @
d372ae68
...
@@ -154,6 +154,14 @@ class TodoService
...
@@ -154,6 +154,14 @@ class TodoService
resolve_todos_for_target
(
awardable
,
current_user
)
resolve_todos_for_target
(
awardable
,
current_user
)
end
end
# When assigning an alert we should:
#
# * create a pending todo for new assignee if alert is assigned
#
def
assign_alert
(
alert
,
current_user
)
create_assignment_todo
(
alert
,
current_user
,
[])
end
# When user marks an issue as todo
# When user marks an issue as todo
def
mark_todo
(
issuable
,
current_user
)
def
mark_todo
(
issuable
,
current_user
)
attributes
=
attributes_for_todo
(
issuable
.
project
,
issuable
,
current_user
,
Todo
::
MARKED
)
attributes
=
attributes_for_todo
(
issuable
.
project
,
issuable
,
current_user
,
Todo
::
MARKED
)
...
@@ -242,10 +250,10 @@ class TodoService
...
@@ -242,10 +250,10 @@ class TodoService
create_mention_todos
(
project
,
target
,
author
,
note
,
skip_users
)
create_mention_todos
(
project
,
target
,
author
,
note
,
skip_users
)
end
end
def
create_assignment_todo
(
issuable
,
author
,
old_assignees
=
[])
def
create_assignment_todo
(
target
,
author
,
old_assignees
=
[])
if
issuable
.
assignees
.
any?
if
target
.
assignees
.
any?
assignees
=
issuable
.
assignees
-
old_assignees
assignees
=
target
.
assignees
-
old_assignees
attributes
=
attributes_for_todo
(
issuable
.
project
,
issuable
,
author
,
Todo
::
ASSIGNED
)
attributes
=
attributes_for_todo
(
target
.
project
,
target
,
author
,
Todo
::
ASSIGNED
)
create_todos
(
assignees
,
attributes
)
create_todos
(
assignees
,
attributes
)
end
end
end
end
...
...
spec/services/todo_service_spec.rb
View file @
d372ae68
...
@@ -27,6 +27,39 @@ describe TodoService do
...
@@ -27,6 +27,39 @@ describe TodoService do
project
.
add_developer
(
skipped
)
project
.
add_developer
(
skipped
)
end
end
shared_examples
'reassigned target'
do
it
'creates a pending todo for new assignee'
do
target_unassigned
.
assignees
=
[
john_doe
]
service
.
send
(
described_method
,
target_unassigned
,
author
)
should_create_todo
(
user:
john_doe
,
target:
target_unassigned
,
action:
Todo
::
ASSIGNED
)
end
it
'does not create a todo if unassigned'
do
target_assigned
.
assignees
=
[]
should_not_create_any_todo
{
service
.
send
(
described_method
,
target_assigned
,
author
)
}
end
it
'creates a todo if new assignee is the current user'
do
target_assigned
.
assignees
=
[
john_doe
]
service
.
send
(
described_method
,
target_assigned
,
john_doe
)
should_create_todo
(
user:
john_doe
,
target:
target_assigned
,
author:
john_doe
,
action:
Todo
::
ASSIGNED
)
end
it
'does not create a todo for guests'
do
service
.
send
(
described_method
,
target_assigned
,
author
)
should_not_create_todo
(
user:
guest
,
target:
target_assigned
,
action:
Todo
::
MENTIONED
)
end
it
'does not create a directly addressed todo for guests'
do
service
.
send
(
described_method
,
addressed_target_assigned
,
author
)
should_not_create_todo
(
user:
guest
,
target:
addressed_target_assigned
,
action:
Todo
::
DIRECTLY_ADDRESSED
)
end
end
describe
'Issues'
do
describe
'Issues'
do
let
(
:issue
)
{
create
(
:issue
,
project:
project
,
assignees:
[
john_doe
],
author:
author
,
description:
"- [ ] Task 1
\n
- [ ] Task 2
#{
mentions
}
"
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
,
assignees:
[
john_doe
],
author:
author
,
description:
"- [ ] Task 1
\n
- [ ] Task 2
#{
mentions
}
"
)
}
let
(
:addressed_issue
)
{
create
(
:issue
,
project:
project
,
assignees:
[
john_doe
],
author:
author
,
description:
"
#{
directly_addressed
}
\n
- [ ] Task 1
\n
- [ ] Task 2"
)
}
let
(
:addressed_issue
)
{
create
(
:issue
,
project:
project
,
assignees:
[
john_doe
],
author:
author
,
description:
"
#{
directly_addressed
}
\n
- [ ] Task 1
\n
- [ ] Task 2"
)
}
...
@@ -522,51 +555,21 @@ describe TodoService do
...
@@ -522,51 +555,21 @@ describe TodoService do
end
end
describe
'#reassigned_issuable'
do
describe
'#reassigned_issuable'
do
shared_examples
'reassigned issuable'
do
let
(
:described_method
)
{
:reassigned_issuable
}
it
'creates a pending todo for new assignee'
do
issuable_unassigned
.
assignees
=
[
john_doe
]
service
.
reassigned_issuable
(
issuable_unassigned
,
author
)
should_create_todo
(
user:
john_doe
,
target:
issuable_unassigned
,
action:
Todo
::
ASSIGNED
)
end
it
'does not create a todo if unassigned'
do
issuable_assigned
.
assignees
=
[]
should_not_create_any_todo
{
service
.
reassigned_issuable
(
issuable_assigned
,
author
)
}
end
it
'creates a todo if new assignee is the current user'
do
issuable_assigned
.
assignees
=
[
john_doe
]
service
.
reassigned_issuable
(
issuable_assigned
,
john_doe
)
should_create_todo
(
user:
john_doe
,
target:
issuable_assigned
,
author:
john_doe
,
action:
Todo
::
ASSIGNED
)
end
it
'does not create a todo for guests'
do
service
.
reassigned_issuable
(
issuable_assigned
,
author
)
should_not_create_todo
(
user:
guest
,
target:
issuable_assigned
,
action:
Todo
::
MENTIONED
)
end
it
'does not create a directly addressed todo for guests'
do
service
.
reassigned_issuable
(
addressed_issuable_assigned
,
author
)
should_not_create_todo
(
user:
guest
,
target:
addressed_issuable_assigned
,
action:
Todo
::
DIRECTLY_ADDRESSED
)
end
end
context
'issuable is a merge request'
do
context
'issuable is a merge request'
do
it_behaves_like
'reassigned
issuable
'
do
it_behaves_like
'reassigned
target
'
do
let
(
:
issuable
_assigned
)
{
create
(
:merge_request
,
source_project:
project
,
author:
author
,
assignees:
[
john_doe
],
description:
"- [ ] Task 1
\n
- [ ] Task 2
#{
mentions
}
"
)
}
let
(
:
target
_assigned
)
{
create
(
:merge_request
,
source_project:
project
,
author:
author
,
assignees:
[
john_doe
],
description:
"- [ ] Task 1
\n
- [ ] Task 2
#{
mentions
}
"
)
}
let
(
:addressed_
issuable
_assigned
)
{
create
(
:merge_request
,
source_project:
project
,
author:
author
,
assignees:
[
john_doe
],
description:
"
#{
directly_addressed
}
\n
- [ ] Task 1
\n
- [ ] Task 2"
)
}
let
(
:addressed_
target
_assigned
)
{
create
(
:merge_request
,
source_project:
project
,
author:
author
,
assignees:
[
john_doe
],
description:
"
#{
directly_addressed
}
\n
- [ ] Task 1
\n
- [ ] Task 2"
)
}
let
(
:
issuable
_unassigned
)
{
create
(
:merge_request
,
source_project:
project
,
author:
author
,
assignees:
[])
}
let
(
:
target
_unassigned
)
{
create
(
:merge_request
,
source_project:
project
,
author:
author
,
assignees:
[])
}
end
end
end
end
context
'issuable is an issue'
do
context
'issuable is an issue'
do
it_behaves_like
'reassigned
issuable
'
do
it_behaves_like
'reassigned
target
'
do
let
(
:
issuable
_assigned
)
{
create
(
:issue
,
project:
project
,
author:
author
,
assignees:
[
john_doe
],
description:
"- [ ] Task 1
\n
- [ ] Task 2
#{
mentions
}
"
)
}
let
(
:
target
_assigned
)
{
create
(
:issue
,
project:
project
,
author:
author
,
assignees:
[
john_doe
],
description:
"- [ ] Task 1
\n
- [ ] Task 2
#{
mentions
}
"
)
}
let
(
:addressed_
issuable
_assigned
)
{
create
(
:issue
,
project:
project
,
author:
author
,
assignees:
[
john_doe
],
description:
"
#{
directly_addressed
}
\n
- [ ] Task 1
\n
- [ ] Task 2"
)
}
let
(
:addressed_
target
_assigned
)
{
create
(
:issue
,
project:
project
,
author:
author
,
assignees:
[
john_doe
],
description:
"
#{
directly_addressed
}
\n
- [ ] Task 1
\n
- [ ] Task 2"
)
}
let
(
:
issuable
_unassigned
)
{
create
(
:issue
,
project:
project
,
author:
author
,
assignees:
[])
}
let
(
:
target
_unassigned
)
{
create
(
:issue
,
project:
project
,
author:
author
,
assignees:
[])
}
end
end
end
end
end
end
...
@@ -756,6 +759,16 @@ describe TodoService do
...
@@ -756,6 +759,16 @@ describe TodoService do
end
end
end
end
describe
'#assign_alert'
do
let
(
:described_method
)
{
:assign_alert
}
it_behaves_like
'reassigned target'
do
let
(
:target_assigned
)
{
create
(
:alert_management_alert
,
project:
project
,
assignees:
[
john_doe
])
}
let
(
:addressed_target_assigned
)
{
create
(
:alert_management_alert
,
project:
project
,
assignees:
[
john_doe
])
}
let
(
:target_unassigned
)
{
create
(
:alert_management_alert
,
project:
project
,
assignees:
[])
}
end
end
describe
'#merge_request_build_failed'
do
describe
'#merge_request_build_failed'
do
let
(
:merge_participants
)
{
[
mr_unassigned
.
author
,
admin
]
}
let
(
:merge_participants
)
{
[
mr_unassigned
.
author
,
admin
]
}
...
...
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