Commit 3d55ab5e authored by Patrick Derichs's avatar Patrick Derichs

Remove create_note from SystemNotesService

Add specs

Update EE::SystemNotesService

Remove obsolete methods url_helpers and content_tag
parent 88c7d32e
......@@ -100,9 +100,7 @@ module SystemNoteService
end
def close_after_error_tracking_resolve(issue, project, author)
body = _('resolved the corresponding error and closed the issue.')
create_note(NoteSummary.new(issue, project, author, body, action: 'closed'))
::SystemNotes::IssuablesService.new(noteable: issue, project: project, author: author).close_after_error_tracking_resolve
end
def change_status(noteable, project, author, status, source = nil)
......@@ -243,23 +241,6 @@ module SystemNoteService
def zoom_link_removed(issue, project, author)
::SystemNotes::ZoomService.new(noteable: issue, project: project, author: author).zoom_link_removed
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
SystemNoteService.prepend_if_ee('EE::SystemNoteService')
......@@ -282,6 +282,12 @@ module SystemNotes
create_note(NoteSummary.new(noteable, project, author, body, action: action))
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
def cross_reference_note_content(gfm_reference)
......
......@@ -161,9 +161,7 @@ module EE
end
def auto_resolve_prometheus_alert(noteable, project, author)
body = 'automatically closed this issue because the alert resolved.'
create_note(NoteSummary.new(noteable, project, author, body, action: 'closed'))
::SystemNotes::IssuablesService.new(noteable: noteable, project: project, author: author).auto_resolve_prometheus_alert
end
end
end
......@@ -44,6 +44,12 @@ module EE
create_note(NoteSummary.new(noteable, project, author, body, action: 'weight'))
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
......@@ -74,4 +74,16 @@ describe ::SystemNotes::IssuablesService do
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
......@@ -220,4 +220,14 @@ describe SystemNoteService do
described_class.abort_add_to_merge_train_when_pipeline_succeeds(noteable, project, author, message)
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
......@@ -63,6 +63,16 @@ describe SystemNoteService do
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
let(:milestone) { double }
......
......@@ -630,4 +630,17 @@ describe ::SystemNotes::IssuablesService do
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
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