diff options
Diffstat (limited to 'app/services/system_notes/issuables_service.rb')
-rw-r--r-- | app/services/system_notes/issuables_service.rb | 25 |
1 files changed, 20 insertions, 5 deletions
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) |