diff options
Diffstat (limited to 'app/services/system_notes')
-rw-r--r-- | app/services/system_notes/alert_management_service.rb | 37 | ||||
-rw-r--r-- | app/services/system_notes/issuables_service.rb | 25 | ||||
-rw-r--r-- | app/services/system_notes/merge_requests_service.rb | 21 |
3 files changed, 76 insertions, 7 deletions
diff --git a/app/services/system_notes/alert_management_service.rb b/app/services/system_notes/alert_management_service.rb new file mode 100644 index 00000000000..55a6a17bbca --- /dev/null +++ b/app/services/system_notes/alert_management_service.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module SystemNotes + class AlertManagementService < ::SystemNotes::BaseService + # Called when the status of an AlertManagement::Alert has changed + # + # alert - AlertManagement::Alert object. + # + # Example Note text: + # + # "changed the status to Acknowledged" + # + # Returns the created Note object + def change_alert_status(alert) + status = AlertManagement::Alert::STATUSES.key(alert.status).to_s.titleize + body = "changed the status to **#{status}**" + + 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 diff --git a/app/services/system_notes/issuables_service.rb b/app/services/system_notes/issuables_service.rb index 7d7ee8d829e..76261aa716e 100644 --- a/app/services/system_notes/issuables_service.rb +++ b/app/services/system_notes/issuables_service.rb @@ -228,7 +228,9 @@ module SystemNotes # A state event which results in a synthetic note will be # created by EventCreateService if change event tracking # is enabled. - unless state_change_tracking_enabled? + if state_change_tracking_enabled? + create_resource_state_event(status: status, mentionable_source: source) + else create_note(NoteSummary.new(noteable, project, author, body, action: action)) end end @@ -288,15 +290,23 @@ module SystemNotes end def close_after_error_tracking_resolve - body = _('resolved the corresponding error and closed the issue.') + if state_change_tracking_enabled? + create_resource_state_event(status: 'closed', close_after_error_tracking_resolve: true) + else + body = 'resolved the corresponding error and closed the issue.' - create_note(NoteSummary.new(noteable, project, author, body, action: 'closed')) + create_note(NoteSummary.new(noteable, project, author, body, action: 'closed')) + end end def auto_resolve_prometheus_alert - body = 'automatically closed this issue because the alert resolved.' + if state_change_tracking_enabled? + create_resource_state_event(status: 'closed', close_auto_resolve_prometheus_alert: true) + else + body = 'automatically closed this issue because the alert resolved.' - create_note(NoteSummary.new(noteable, project, author, body, action: 'closed')) + create_note(NoteSummary.new(noteable, project, author, body, action: 'closed')) + end end private @@ -324,6 +334,11 @@ module SystemNotes note_text =~ /\A#{cross_reference_note_prefix}/i end + def create_resource_state_event(params) + ResourceEvents::ChangeStateService.new(resource: noteable, user: author) + .execute(params) + end + def state_change_tracking_enabled? noteable.respond_to?(:resource_state_events) && ::Feature.enabled?(:track_resource_state_change_events, noteable.project) diff --git a/app/services/system_notes/merge_requests_service.rb b/app/services/system_notes/merge_requests_service.rb index baf26245eb9..9b5c9ba20b2 100644 --- a/app/services/system_notes/merge_requests_service.rb +++ b/app/services/system_notes/merge_requests_service.rb @@ -150,7 +150,24 @@ module SystemNotes create_note(summary) end + + # Called when the merge request is approved by user + # + # Example Note text: + # + # "approved this merge request" + # + # Returns the created Note object + def approve_mr + body = "approved this merge request" + + create_note(NoteSummary.new(noteable, project, author, body, action: 'approved')) + end + + def unapprove_mr + body = "unapproved this merge request" + + create_note(NoteSummary.new(noteable, project, author, body, action: 'unapproved')) + end end end - -SystemNotes::MergeRequestsService.prepend_if_ee('::EE::SystemNotes::MergeRequestsService') |