Commit 1fc5bd03 authored by Sean McGivern's avatar Sean McGivern

Merge branch '17597-remove-create-note-from-system-note-service-pd' into 'master'

Move two methods to the more specialized system note services

See merge request gitlab-org/gitlab!23443
parents 1043e937 3d55ab5e
...@@ -100,9 +100,7 @@ module SystemNoteService ...@@ -100,9 +100,7 @@ module SystemNoteService
end end
def close_after_error_tracking_resolve(issue, project, author) def close_after_error_tracking_resolve(issue, project, author)
body = _('resolved the corresponding error and closed the issue.') ::SystemNotes::IssuablesService.new(noteable: issue, project: project, author: author).close_after_error_tracking_resolve
create_note(NoteSummary.new(issue, project, author, body, action: 'closed'))
end end
def change_status(noteable, project, author, status, source = nil) def change_status(noteable, project, author, status, source = nil)
...@@ -243,23 +241,6 @@ module SystemNoteService ...@@ -243,23 +241,6 @@ module SystemNoteService
def zoom_link_removed(issue, project, author) def zoom_link_removed(issue, project, author)
::SystemNotes::ZoomService.new(noteable: issue, project: project, author: author).zoom_link_removed ::SystemNotes::ZoomService.new(noteable: issue, project: project, author: author).zoom_link_removed
end end
private
def create_note(note_summary)
note = Note.create(note_summary.note.merge(system: true))
note.system_note_metadata = SystemNoteMetadata.new(note_summary.metadata) if note_summary.metadata?
note
end
def url_helpers
@url_helpers ||= Gitlab::Routing.url_helpers
end
def content_tag(*args)
ActionController::Base.helpers.content_tag(*args)
end
end end
SystemNoteService.prepend_if_ee('EE::SystemNoteService') SystemNoteService.prepend_if_ee('EE::SystemNoteService')
...@@ -282,6 +282,12 @@ module SystemNotes ...@@ -282,6 +282,12 @@ module SystemNotes
create_note(NoteSummary.new(noteable, project, author, body, action: action)) create_note(NoteSummary.new(noteable, project, author, body, action: action))
end end
def close_after_error_tracking_resolve
body = _('resolved the corresponding error and closed the issue.')
create_note(NoteSummary.new(noteable, project, author, body, action: 'closed'))
end
private private
def cross_reference_note_content(gfm_reference) def cross_reference_note_content(gfm_reference)
......
...@@ -161,9 +161,7 @@ module EE ...@@ -161,9 +161,7 @@ module EE
end end
def auto_resolve_prometheus_alert(noteable, project, author) def auto_resolve_prometheus_alert(noteable, project, author)
body = 'automatically closed this issue because the alert resolved.' ::SystemNotes::IssuablesService.new(noteable: noteable, project: project, author: author).auto_resolve_prometheus_alert
create_note(NoteSummary.new(noteable, project, author, body, action: 'closed'))
end end
end end
end end
...@@ -44,6 +44,12 @@ module EE ...@@ -44,6 +44,12 @@ module EE
create_note(NoteSummary.new(noteable, project, author, body, action: 'weight')) create_note(NoteSummary.new(noteable, project, author, body, action: 'weight'))
end end
def auto_resolve_prometheus_alert
body = 'automatically closed this issue because the alert resolved.'
create_note(NoteSummary.new(noteable, project, author, body, action: 'closed'))
end
end end
end end
end end
...@@ -74,4 +74,16 @@ describe ::SystemNotes::IssuablesService do ...@@ -74,4 +74,16 @@ describe ::SystemNotes::IssuablesService do
end end
end end
end end
describe '#auto_resolve_prometheus_alert' do
subject { service.auto_resolve_prometheus_alert }
it_behaves_like 'a system note' do
let(:action) { 'closed' }
end
it 'creates the expected system note' do
expect(subject.note).to eq('automatically closed this issue because the alert resolved.')
end
end
end end
...@@ -220,4 +220,14 @@ describe SystemNoteService do ...@@ -220,4 +220,14 @@ describe SystemNoteService do
described_class.abort_add_to_merge_train_when_pipeline_succeeds(noteable, project, author, message) described_class.abort_add_to_merge_train_when_pipeline_succeeds(noteable, project, author, message)
end end
end end
describe '.auto_resolve_prometheus_alert' do
it 'calls IssuableService' do
expect_next_instance_of(::SystemNotes::IssuablesService) do |service|
expect(service).to receive(:auto_resolve_prometheus_alert)
end
described_class.auto_resolve_prometheus_alert(noteable, project, author)
end
end
end end
...@@ -63,6 +63,16 @@ describe SystemNoteService do ...@@ -63,6 +63,16 @@ describe SystemNoteService do
end end
end end
describe '.close_after_error_tracking_resolve' do
it 'calls IssuableService' do
expect_next_instance_of(::SystemNotes::IssuablesService) do |service|
expect(service).to receive(:close_after_error_tracking_resolve)
end
described_class.close_after_error_tracking_resolve(noteable, project, author)
end
end
describe '.change_milestone' do describe '.change_milestone' do
let(:milestone) { double } let(:milestone) { double }
......
...@@ -630,4 +630,17 @@ describe ::SystemNotes::IssuablesService do ...@@ -630,4 +630,17 @@ describe ::SystemNotes::IssuablesService do
end end
end end
end end
describe '#close_after_error_tracking_resolve' do
subject { service.close_after_error_tracking_resolve }
it_behaves_like 'a system note' do
let(:action) { 'closed' }
end
it 'creates the expected system note' do
expect(subject.note)
.to eq('resolved the corresponding error and closed the issue.')
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