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
d7ea29d5
Commit
d7ea29d5
authored
Dec 02, 2021
by
David Barr
Committed by
Patrick Bajao
Dec 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create system note for attention requests
parent
37fbd5b3
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
136 additions
and
10 deletions
+136
-10
app/helpers/system_note_helper.rb
app/helpers/system_note_helper.rb
+3
-1
app/models/system_note_metadata.rb
app/models/system_note_metadata.rb
+1
-0
app/services/merge_requests/toggle_attention_requested_service.rb
...ices/merge_requests/toggle_attention_requested_service.rb
+11
-0
app/services/system_note_service.rb
app/services/system_note_service.rb
+8
-0
app/services/system_notes/issuables_service.rb
app/services/system_notes/issuables_service.rb
+39
-9
spec/services/merge_requests/toggle_attention_requested_service_spec.rb
...merge_requests/toggle_attention_requested_service_spec.rb
+14
-0
spec/services/system_note_service_spec.rb
spec/services/system_note_service_spec.rb
+24
-0
spec/services/system_notes/issuables_service_spec.rb
spec/services/system_notes/issuables_service_spec.rb
+36
-0
No files found.
app/helpers/system_note_helper.rb
View file @
d7ea29d5
...
...
@@ -40,7 +40,9 @@ module SystemNoteHelper
'new_alert_added'
=>
'warning'
,
'severity'
=>
'information-o'
,
'cloned'
=>
'documents'
,
'issue_type'
=>
'pencil-square'
'issue_type'
=>
'pencil-square'
,
'attention_requested'
=>
'user'
,
'attention_request_removed'
=>
'user'
}.
freeze
def
system_note_icon_name
(
note
)
...
...
app/models/system_note_metadata.rb
View file @
d7ea29d5
...
...
@@ -24,6 +24,7 @@ class SystemNoteMetadata < ApplicationRecord
opened closed merged duplicate locked unlocked outdated reviewer
tag due_date pinned_embed cherry_pick health_status approved unapproved
status alert_issue_added relate unrelate new_alert_added severity
attention_requested attention_request_removed
]
.
freeze
validates
:note
,
presence:
true
,
unless: :importing?
...
...
app/services/merge_requests/toggle_attention_requested_service.rb
View file @
d7ea29d5
...
...
@@ -19,7 +19,10 @@ module MergeRequests
update_state
(
assignee
)
if
reviewer
&
.
attention_requested?
||
assignee
&
.
attention_requested?
create_attention_request_note
notity_user
else
create_remove_attention_request_note
end
success
...
...
@@ -35,6 +38,14 @@ module MergeRequests
todo_service
.
create_attention_requested_todo
(
merge_request
,
current_user
,
user
)
end
def
create_attention_request_note
SystemNoteService
.
request_attention
(
merge_request
,
merge_request
.
project
,
current_user
,
user
)
end
def
create_remove_attention_request_note
SystemNoteService
.
remove_attention_request
(
merge_request
,
merge_request
.
project
,
current_user
,
user
)
end
def
assignee
merge_request
.
find_assignee
(
user
)
end
...
...
app/services/system_note_service.rb
View file @
d7ea29d5
...
...
@@ -115,6 +115,14 @@ module SystemNoteService
::
SystemNotes
::
IssuablesService
.
new
(
noteable:
noteable
,
project:
project
,
author:
author
).
change_status
(
status
,
source
)
end
def
request_attention
(
noteable
,
project
,
author
,
user
)
::
SystemNotes
::
IssuablesService
.
new
(
noteable:
noteable
,
project:
project
,
author:
author
).
request_attention
(
user
)
end
def
remove_attention_request
(
noteable
,
project
,
author
,
user
)
::
SystemNotes
::
IssuablesService
.
new
(
noteable:
noteable
,
project:
project
,
author:
author
).
remove_attention_request
(
user
)
end
# Called when 'merge when pipeline succeeds' is executed
def
merge_when_pipeline_succeeds
(
noteable
,
project
,
author
,
sha
)
::
SystemNotes
::
MergeRequestsService
.
new
(
noteable:
noteable
,
project:
project
,
author:
author
).
merge_when_pipeline_succeeds
(
sha
)
...
...
app/services/system_notes/issuables_service.rb
View file @
d7ea29d5
...
...
@@ -323,23 +323,34 @@ module SystemNotes
existing_mentions_for
(
mentioned_in
,
noteable
,
notes
).
exists?
end
# Called when a
Noteable has been marked as a duplicate of another Issu
e
# Called when a
user's attention has been requested for a Notabl
e
#
#
canonical_issue - Issue that this is a duplicate of
#
user - User's whos attention has been requested
#
# Example Note text:
#
# "marked this issue as a duplicate of #1234"
#
# "marked this issue as a duplicate of other_project#5678"
# "requested attention from @eli.wisoky"
#
# Returns the created Note object
def
mark_duplicate_issue
(
canonical_issue
)
body
=
"
marked this issue as a duplicate of
#{
canonical_issue
.
to_reference
(
project
)
}
"
def
request_attention
(
user
)
body
=
"
requested attention from
#{
user
.
to_reference
}
"
issue_activity_counter
.
track_issue_marked_as_duplicate_action
(
author:
author
)
if
noteable
.
is_a?
(
Issue
)
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'attention_requested'
))
end
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'duplicate'
))
# Called when a user's attention request has been removed for a Notable
#
# user - User's whos attention request has been removed
#
# Example Note text:
#
# "removed attention request from @eli.wisoky"
#
# Returns the created Note object
def
remove_attention_request
(
user
)
body
=
"removed attention request from
#{
user
.
to_reference
}
"
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'attention_request_removed'
))
end
# Called when a Noteable has been marked as the canonical Issue of a duplicate
...
...
@@ -358,6 +369,25 @@ module SystemNotes
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'duplicate'
))
end
# Called when a Noteable has been marked as a duplicate of another Issue
#
# canonical_issue - Issue that this is a duplicate of
#
# Example Note text:
#
# "marked this issue as a duplicate of #1234"
#
# "marked this issue as a duplicate of other_project#5678"
#
# Returns the created Note object
def
mark_duplicate_issue
(
canonical_issue
)
body
=
"marked this issue as a duplicate of
#{
canonical_issue
.
to_reference
(
project
)
}
"
issue_activity_counter
.
track_issue_marked_as_duplicate_action
(
author:
author
)
if
noteable
.
is_a?
(
Issue
)
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'duplicate'
))
end
def
add_email_participants
(
body
)
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
))
end
...
...
spec/services/merge_requests/toggle_attention_requested_service_spec.rb
View file @
d7ea29d5
...
...
@@ -19,6 +19,8 @@ RSpec.describe MergeRequests::ToggleAttentionRequestedService do
allow
(
NotificationService
).
to
receive
(
:new
)
{
notification_service
}
allow
(
service
).
to
receive
(
:todo_service
).
and_return
(
todo_service
)
allow
(
service
).
to
receive
(
:notification_service
).
and_return
(
notification_service
)
allow
(
SystemNoteService
).
to
receive
(
:request_attention
)
allow
(
SystemNoteService
).
to
receive
(
:remove_attention_request
)
project
.
add_developer
(
current_user
)
project
.
add_developer
(
user
)
...
...
@@ -93,6 +95,12 @@ RSpec.describe MergeRequests::ToggleAttentionRequestedService do
service
.
execute
end
it
'creates a request attention system note'
do
expect
(
SystemNoteService
).
to
receive
(
:request_attention
).
with
(
merge_request
,
merge_request
.
project
,
current_user
,
assignee_user
)
service
.
execute
end
end
context
'assignee is the same as reviewer'
do
...
...
@@ -132,6 +140,12 @@ RSpec.describe MergeRequests::ToggleAttentionRequestedService do
service
.
execute
end
it
'creates a remove attention request system note'
do
expect
(
SystemNoteService
).
to
receive
(
:remove_attention_request
).
with
(
merge_request
,
merge_request
.
project
,
current_user
,
user
)
service
.
execute
end
end
end
end
spec/services/system_note_service_spec.rb
View file @
d7ea29d5
...
...
@@ -146,6 +146,30 @@ RSpec.describe SystemNoteService do
end
end
describe
'.request_attention'
do
let
(
:user
)
{
double
}
it
'calls IssuableService'
do
expect_next_instance_of
(
::
SystemNotes
::
IssuablesService
)
do
|
service
|
expect
(
service
).
to
receive
(
:request_attention
).
with
(
user
)
end
described_class
.
request_attention
(
noteable
,
project
,
author
,
user
)
end
end
describe
'.remove_attention_request'
do
let
(
:user
)
{
double
}
it
'calls IssuableService'
do
expect_next_instance_of
(
::
SystemNotes
::
IssuablesService
)
do
|
service
|
expect
(
service
).
to
receive
(
:remove_attention_request
).
with
(
user
)
end
described_class
.
remove_attention_request
(
noteable
,
project
,
author
,
user
)
end
end
describe
'.merge_when_pipeline_succeeds'
do
it
'calls MergeRequestsService'
do
sha
=
double
...
...
spec/services/system_notes/issuables_service_spec.rb
View file @
d7ea29d5
...
...
@@ -199,6 +199,42 @@ RSpec.describe ::SystemNotes::IssuablesService do
end
end
describe
'#request_attention'
do
subject
{
service
.
request_attention
(
user
)
}
let
(
:user
)
{
create
(
:user
)
}
it_behaves_like
'a system note'
do
let
(
:action
)
{
'attention_requested'
}
end
context
'when attention requested'
do
it_behaves_like
'a note with overridable created_at'
it
'sets the note text'
do
expect
(
subject
.
note
).
to
eq
"requested attention from @
#{
user
.
username
}
"
end
end
end
describe
'#remove_attention_request'
do
subject
{
service
.
remove_attention_request
(
user
)
}
let
(
:user
)
{
create
(
:user
)
}
it_behaves_like
'a system note'
do
let
(
:action
)
{
'attention_request_removed'
}
end
context
'when attention request is removed'
do
it_behaves_like
'a note with overridable created_at'
it
'sets the note text'
do
expect
(
subject
.
note
).
to
eq
"removed attention request from @
#{
user
.
username
}
"
end
end
end
describe
'#change_title'
do
let
(
:noteable
)
{
create
(
:issue
,
project:
project
,
title:
'Lorem ipsum'
)
}
...
...
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