Commit 5e5de233 authored by Sean Arnold's avatar Sean Arnold

Check if alert resolved before adding note

- Remove SystemNoteService addition
- Small tidy ups
parent 32fd25ea
...@@ -33,7 +33,7 @@ module Issues ...@@ -33,7 +33,7 @@ module Issues
notification_service.async.close_issue(issue, current_user, closed_via: closed_via) if notifications notification_service.async.close_issue(issue, current_user, closed_via: closed_via) if notifications
todo_service.close_issue(issue, current_user) todo_service.close_issue(issue, current_user)
resolve_alert(issue, system_note) resolve_alert(issue)
execute_hooks(issue, 'close') execute_hooks(issue, 'close')
invalidate_cache_counts(issue, users: issue.assignees) invalidate_cache_counts(issue, users: issue.assignees)
issue.update_project_counter_caches issue.update_project_counter_caches
...@@ -59,11 +59,12 @@ module Issues ...@@ -59,11 +59,12 @@ module Issues
SystemNoteService.change_status(issue, issue.project, current_user, issue.state, current_commit) SystemNoteService.change_status(issue, issue.project, current_user, issue.state, current_commit)
end end
def resolve_alert(issue, system_note) def resolve_alert(issue)
return unless alert = issue.alert_management_alert return unless alert = issue.alert_management_alert
return if alert.resolved?
if alert.resolve if alert.resolve
SystemNoteService.closed_alert_issue(alert, issue, current_user) if system_note SystemNotes::AlertManagementService.new(noteable: alert, project: alert.project, author: current_user).closed_alert_issue(issue)
else else
Gitlab::AppLogger.warn( Gitlab::AppLogger.warn(
message: 'Cannot resolve an associated Alert Management alert', message: 'Cannot resolve an associated Alert Management alert',
......
...@@ -300,10 +300,6 @@ module SystemNoteService ...@@ -300,10 +300,6 @@ module SystemNoteService
::SystemNotes::AlertManagementService.new(noteable: alert, project: alert.project, author: author).new_alert_issue(issue) ::SystemNotes::AlertManagementService.new(noteable: alert, project: alert.project, author: author).new_alert_issue(issue)
end end
def closed_alert_issue(alert, issue, author)
::SystemNotes::AlertManagementService.new(noteable: alert, project: alert.project, author: author).closed_alert_issue(issue)
end
private private
def merge_requests_service(noteable, project, author) def merge_requests_service(noteable, project, author)
......
...@@ -20,7 +20,6 @@ module SystemNotes ...@@ -20,7 +20,6 @@ module SystemNotes
# Called when an issue is created based on an AlertManagement::Alert # Called when an issue is created based on an AlertManagement::Alert
# #
# alert - AlertManagement::Alert object.
# issue - Issue object. # issue - Issue object.
# #
# Example Note text: # Example Note text:
...@@ -34,9 +33,8 @@ module SystemNotes ...@@ -34,9 +33,8 @@ module SystemNotes
create_note(NoteSummary.new(noteable, project, author, body, action: 'alert_issue_added')) create_note(NoteSummary.new(noteable, project, author, body, action: 'alert_issue_added'))
end end
# Called when an AlertManagement::Alert is resolved due to the associated alert being closed # Called when an AlertManagement::Alert is resolved due to the associated issue being closed
# #
# alert - AlertManagement::Alert object.
# issue - Issue object. # issue - Issue object.
# #
# Example Note text: # Example Note text:
......
...@@ -257,7 +257,9 @@ RSpec.describe Issues::CloseService do ...@@ -257,7 +257,9 @@ RSpec.describe Issues::CloseService do
let!(:alert) { create(:alert_management_alert, issue: issue, project: project) } let!(:alert) { create(:alert_management_alert, issue: issue, project: project) }
it 'resolves an alert and sends a system note' do it 'resolves an alert and sends a system note' do
expect(SystemNoteService).to receive(:closed_alert_issue).with(alert, issue, instance_of(User)) expect_next_instance_of(SystemNotes::AlertManagementService) do |notes_service|
expect(notes_service).to receive(:closed_alert_issue).with(issue)
end
close_issue close_issue
......
...@@ -705,16 +705,4 @@ RSpec.describe SystemNoteService do ...@@ -705,16 +705,4 @@ RSpec.describe SystemNoteService do
described_class.new_alert_issue(alert, alert.issue, author) described_class.new_alert_issue(alert, alert.issue, author)
end end
end end
describe '.closed_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(:closed_alert_issue).with(alert.issue)
end
described_class.closed_alert_issue(alert, alert.issue, author)
end
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