|
22 | 22 | import java.util.Collections; |
23 | 23 | import java.util.HashSet; |
24 | 24 | import java.util.List; |
| 25 | +import java.util.Optional; |
25 | 26 | import java.util.Set; |
26 | 27 | import lombok.RequiredArgsConstructor; |
27 | 28 | import lombok.extern.log4j.Log4j2; |
@@ -213,26 +214,40 @@ private void processRunForHeliosDeployment(GHWorkflowRun workflowRun) throws IOE |
213 | 214 | mapWorkflowRunStatus(workflowRun.getStatus(), workflowRun.getConclusion()); |
214 | 215 | log.debug("Mapped status {} to {}", workflowRun.getStatus(), mappedStatus); |
215 | 216 |
|
216 | | - if (mappedStatus == HeliosDeployment.Status.FAILED |
217 | | - && heliosDeployment.getStatus() != HeliosDeployment.Status.FAILED |
218 | | - && deploymentFailureNotificationDecider.shouldNotify(workflowRun, |
219 | | - heliosDeployment.getCreator())) { |
220 | | - log.info("Sending failure notification in WorkflowRunSyncService to {}", |
221 | | - heliosDeployment.getCreator().getNotificationEmail()); |
222 | | - notificationPublisherService.send( |
223 | | - heliosDeployment.getCreator(), |
224 | | - new DeploymentFailurePayload( |
225 | | - heliosDeployment.getCreator().getLogin(), |
226 | | - heliosDeployment.getBranchName(), |
227 | | - String.valueOf(heliosDeployment.getPullRequest().getNumber()), |
228 | | - heliosDeployment.getEnvironment().getName(), |
229 | | - workflowRun.getHtmlUrl().toString(), |
230 | | - heliosDeployment.getEnvironment().getRepository().getRepositoryId() |
231 | | - .toString(), |
232 | | - heliosDeployment.getEnvironment().getRepository().getNameWithOwner() |
233 | | - ) |
234 | | - ); |
| 217 | + try { |
| 218 | + if (mappedStatus == HeliosDeployment.Status.FAILED |
| 219 | + && heliosDeployment.getStatus() != HeliosDeployment.Status.FAILED |
| 220 | + && deploymentFailureNotificationDecider.shouldNotify(workflowRun, |
| 221 | + heliosDeployment.getCreator())) { |
| 222 | + log.info("Sending failure notification in WorkflowRunSyncService to {}", |
| 223 | + heliosDeployment.getCreator().getNotificationEmail()); |
| 224 | + |
| 225 | + final String prNumber = Optional.ofNullable(heliosDeployment.getPullRequest()) |
| 226 | + .map(PullRequest::getNumber) |
| 227 | + .map(String::valueOf) |
| 228 | + .orElse(""); |
| 229 | + |
| 230 | + notificationPublisherService.send( |
| 231 | + heliosDeployment.getCreator(), |
| 232 | + new DeploymentFailurePayload( |
| 233 | + heliosDeployment.getCreator().getLogin(), |
| 234 | + heliosDeployment.getBranchName(), |
| 235 | + prNumber, |
| 236 | + heliosDeployment.getEnvironment().getName(), |
| 237 | + workflowRun.getHtmlUrl().toString(), |
| 238 | + heliosDeployment.getEnvironment().getRepository().getRepositoryId() |
| 239 | + .toString(), |
| 240 | + heliosDeployment.getEnvironment().getRepository().getNameWithOwner() |
| 241 | + ) |
| 242 | + ); |
| 243 | + } |
| 244 | + } catch (Exception e) { |
| 245 | + log.warn( |
| 246 | + "Failed to send deployment failure notification for workflow run {}: {}", |
| 247 | + workflowRun.getId(), |
| 248 | + e.getMessage()); |
235 | 249 | } |
| 250 | + |
236 | 251 | // Update the deployment status |
237 | 252 | heliosDeployment.setStatus(mappedStatus); |
238 | 253 |
|
|
0 commit comments