Commit d7ea29d5 authored by David Barr's avatar David Barr Committed by Patrick Bajao

Create system note for attention requests

parent 37fbd5b3
...@@ -40,7 +40,9 @@ module SystemNoteHelper ...@@ -40,7 +40,9 @@ module SystemNoteHelper
'new_alert_added' => 'warning', 'new_alert_added' => 'warning',
'severity' => 'information-o', 'severity' => 'information-o',
'cloned' => 'documents', 'cloned' => 'documents',
'issue_type' => 'pencil-square' 'issue_type' => 'pencil-square',
'attention_requested' => 'user',
'attention_request_removed' => 'user'
}.freeze }.freeze
def system_note_icon_name(note) def system_note_icon_name(note)
......
...@@ -24,6 +24,7 @@ class SystemNoteMetadata < ApplicationRecord ...@@ -24,6 +24,7 @@ class SystemNoteMetadata < ApplicationRecord
opened closed merged duplicate locked unlocked outdated reviewer opened closed merged duplicate locked unlocked outdated reviewer
tag due_date pinned_embed cherry_pick health_status approved unapproved tag due_date pinned_embed cherry_pick health_status approved unapproved
status alert_issue_added relate unrelate new_alert_added severity status alert_issue_added relate unrelate new_alert_added severity
attention_requested attention_request_removed
].freeze ].freeze
validates :note, presence: true, unless: :importing? validates :note, presence: true, unless: :importing?
......
...@@ -19,7 +19,10 @@ module MergeRequests ...@@ -19,7 +19,10 @@ module MergeRequests
update_state(assignee) update_state(assignee)
if reviewer&.attention_requested? || assignee&.attention_requested? if reviewer&.attention_requested? || assignee&.attention_requested?
create_attention_request_note
notity_user notity_user
else
create_remove_attention_request_note
end end
success success
...@@ -35,6 +38,14 @@ module MergeRequests ...@@ -35,6 +38,14 @@ module MergeRequests
todo_service.create_attention_requested_todo(merge_request, current_user, user) todo_service.create_attention_requested_todo(merge_request, current_user, user)
end 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 def assignee
merge_request.find_assignee(user) merge_request.find_assignee(user)
end end
......
...@@ -115,6 +115,14 @@ module SystemNoteService ...@@ -115,6 +115,14 @@ module SystemNoteService
::SystemNotes::IssuablesService.new(noteable: noteable, project: project, author: author).change_status(status, source) ::SystemNotes::IssuablesService.new(noteable: noteable, project: project, author: author).change_status(status, source)
end 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 # Called when 'merge when pipeline succeeds' is executed
def merge_when_pipeline_succeeds(noteable, project, author, sha) def merge_when_pipeline_succeeds(noteable, project, author, sha)
::SystemNotes::MergeRequestsService.new(noteable: noteable, project: project, author: author).merge_when_pipeline_succeeds(sha) ::SystemNotes::MergeRequestsService.new(noteable: noteable, project: project, author: author).merge_when_pipeline_succeeds(sha)
......
...@@ -323,23 +323,34 @@ module SystemNotes ...@@ -323,23 +323,34 @@ module SystemNotes
existing_mentions_for(mentioned_in, noteable, notes).exists? existing_mentions_for(mentioned_in, noteable, notes).exists?
end end
# Called when a Noteable has been marked as a duplicate of another Issue # Called when a user's attention has been requested for a Notable
# #
# canonical_issue - Issue that this is a duplicate of # user - User's whos attention has been requested
# #
# Example Note text: # Example Note text:
# #
# "marked this issue as a duplicate of #1234" # "requested attention from @eli.wisoky"
#
# "marked this issue as a duplicate of other_project#5678"
# #
# Returns the created Note object # Returns the created Note object
def mark_duplicate_issue(canonical_issue) def request_attention(user)
body = "marked this issue as a duplicate of #{canonical_issue.to_reference(project)}" 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 end
# Called when a Noteable has been marked as the canonical Issue of a duplicate # Called when a Noteable has been marked as the canonical Issue of a duplicate
...@@ -358,6 +369,25 @@ module SystemNotes ...@@ -358,6 +369,25 @@ module SystemNotes
create_note(NoteSummary.new(noteable, project, author, body, action: 'duplicate')) create_note(NoteSummary.new(noteable, project, author, body, action: 'duplicate'))
end 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) def add_email_participants(body)
create_note(NoteSummary.new(noteable, project, author, body)) create_note(NoteSummary.new(noteable, project, author, body))
end end
......
...@@ -19,6 +19,8 @@ RSpec.describe MergeRequests::ToggleAttentionRequestedService do ...@@ -19,6 +19,8 @@ RSpec.describe MergeRequests::ToggleAttentionRequestedService do
allow(NotificationService).to receive(:new) { notification_service } allow(NotificationService).to receive(:new) { notification_service }
allow(service).to receive(:todo_service).and_return(todo_service) allow(service).to receive(:todo_service).and_return(todo_service)
allow(service).to receive(:notification_service).and_return(notification_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(current_user)
project.add_developer(user) project.add_developer(user)
...@@ -93,6 +95,12 @@ RSpec.describe MergeRequests::ToggleAttentionRequestedService do ...@@ -93,6 +95,12 @@ RSpec.describe MergeRequests::ToggleAttentionRequestedService do
service.execute service.execute
end 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 end
context 'assignee is the same as reviewer' do context 'assignee is the same as reviewer' do
...@@ -132,6 +140,12 @@ RSpec.describe MergeRequests::ToggleAttentionRequestedService do ...@@ -132,6 +140,12 @@ RSpec.describe MergeRequests::ToggleAttentionRequestedService do
service.execute service.execute
end 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 end
end end
...@@ -146,6 +146,30 @@ RSpec.describe SystemNoteService do ...@@ -146,6 +146,30 @@ RSpec.describe SystemNoteService do
end end
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 describe '.merge_when_pipeline_succeeds' do
it 'calls MergeRequestsService' do it 'calls MergeRequestsService' do
sha = double sha = double
......
...@@ -199,6 +199,42 @@ RSpec.describe ::SystemNotes::IssuablesService do ...@@ -199,6 +199,42 @@ RSpec.describe ::SystemNotes::IssuablesService do
end end
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 describe '#change_title' do
let(:noteable) { create(:issue, project: project, title: 'Lorem ipsum') } let(:noteable) { create(:issue, project: project, title: 'Lorem ipsum') }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment