From 9f46488805e86b1bc341ea1620b866016c2ce5ed Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 20 May 2020 14:34:42 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-0-stable-ee --- .../incident_management/process_alert_worker.rb | 25 ++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'app/workers/incident_management') diff --git a/app/workers/incident_management/process_alert_worker.rb b/app/workers/incident_management/process_alert_worker.rb index 8d4294cc231..2ce9fe359b5 100644 --- a/app/workers/incident_management/process_alert_worker.rb +++ b/app/workers/incident_management/process_alert_worker.rb @@ -7,11 +7,14 @@ module IncidentManagement queue_namespace :incident_management feature_category :incident_management - def perform(project_id, alert) + def perform(project_id, alert_payload, am_alert_id = nil) project = find_project(project_id) return unless project - create_issue(project, alert) + new_issue = create_issue(project, alert_payload) + return unless am_alert_id && new_issue.persisted? + + link_issue_with_alert(am_alert_id, new_issue.id) end private @@ -20,10 +23,24 @@ module IncidentManagement Project.find_by_id(project_id) end - def create_issue(project, alert) + def create_issue(project, alert_payload) IncidentManagement::CreateIssueService - .new(project, alert) + .new(project, alert_payload) .execute end + + def link_issue_with_alert(alert_id, issue_id) + alert = AlertManagement::Alert.find_by_id(alert_id) + return unless alert + + return if alert.update(issue_id: issue_id) + + Gitlab::AppLogger.warn( + message: 'Cannot link an Issue with Alert', + issue_id: issue_id, + alert_id: alert_id, + alert_errors: alert.errors.messages + ) + end end end -- cgit v1.2.1