Commit 22637ca6 authored by Sarah Yasonik's avatar Sarah Yasonik Committed by Douglas Barbosa Alexandre

Add system note for alert when creating issue

parent 7e4b0297
......@@ -32,7 +32,8 @@ module SystemNoteHelper
'designs_modified' => 'doc-image',
'designs_removed' => 'doc-image',
'designs_discussion_added' => 'doc-image',
'status' => 'status'
'status' => 'status',
'alert_issue_added' => 'issues'
}.freeze
def system_note_icon_name(note)
......
......@@ -19,7 +19,7 @@ class SystemNoteMetadata < ApplicationRecord
title time_tracking branch milestone discussion task moved
opened closed merged duplicate locked unlocked outdated
tag due_date pinned_embed cherry_pick health_status approved unapproved
status
status alert_issue_added
].freeze
validates :note, presence: true
......
......@@ -21,6 +21,8 @@ module AlertManagement
return error(result.message, issue) if result.error?
return error(object_errors(alert), issue) unless associate_alert_with_issue(issue)
SystemNoteService.new_alert_issue(alert, issue, user)
result
end
......
......@@ -296,6 +296,10 @@ module SystemNoteService
::SystemNotes::AlertManagementService.new(noteable: alert, project: alert.project, author: author).change_alert_status(alert)
end
def new_alert_issue(alert, issue, author)
::SystemNotes::AlertManagementService.new(noteable: alert, project: alert.project, author: author).new_alert_issue(alert, issue)
end
private
def merge_requests_service(noteable, project, author)
......
......@@ -17,5 +17,21 @@ module SystemNotes
create_note(NoteSummary.new(noteable, project, author, body, action: 'status'))
end
# Called when an issue is created based on an AlertManagement::Alert
#
# alert - AlertManagement::Alert object.
# issue - Issue object.
#
# Example Note text:
#
# "created issue #17 for this alert"
#
# Returns the created Note object
def new_alert_issue(alert, issue)
body = "created issue #{issue.to_reference(project)} for this alert"
create_note(NoteSummary.new(noteable, project, author, body, action: 'alert_issue_added'))
end
end
end
---
title: Add system note for alert when creating issue
merge_request: 36370
author:
type: added
......@@ -46,6 +46,10 @@ RSpec.describe AlertManagement::CreateAlertIssueService do
expect(alert.reload.issue_id).to eq(created_issue.id)
end
it 'creates a system note' do
expect { execute }.to change { alert.reload.notes.count }.by(1)
end
end
shared_examples 'setting an issue attributes' do
......
......@@ -693,4 +693,16 @@ RSpec.describe SystemNoteService do
described_class.change_alert_status(alert, author)
end
end
describe '.new_alert_issue' do
let(:alert) { build(:alert_management_alert, :with_issue) }
it 'calls AlertManagementService' do
expect_next_instance_of(SystemNotes::AlertManagementService) do |service|
expect(service).to receive(:new_alert_issue).with(alert, alert.issue)
end
described_class.new_alert_issue(alert, alert.issue, author)
end
end
end
......@@ -5,8 +5,7 @@ require 'spec_helper'
RSpec.describe ::SystemNotes::AlertManagementService do
let_it_be(:author) { create(:user) }
let_it_be(:project) { create(:project, :repository) }
let(:noteable) { create(:alert_management_alert, :acknowledged, project: project) }
let_it_be(:noteable) { create(:alert_management_alert, :with_issue, :acknowledged, project: project) }
describe '#change_alert_status' do
subject { described_class.new(noteable: noteable, project: project, author: author).change_alert_status(noteable) }
......@@ -19,4 +18,18 @@ RSpec.describe ::SystemNotes::AlertManagementService do
expect(subject.note).to eq("changed the status to **Acknowledged**")
end
end
describe '#new_alert_issue' do
let_it_be(:issue) { noteable.issue }
subject { described_class.new(noteable: noteable, project: project, author: author).new_alert_issue(noteable, issue) }
it_behaves_like 'a system note' do
let(:action) { 'alert_issue_added' }
end
it 'has the appropriate message' do
expect(subject.note).to eq("created issue #{issue.to_reference(project)} for this alert")
end
end
end
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