Skip to content

Commit 3d3626a

Browse files
authored
fix: deployment notification null pr number issue (#703)
1 parent a7f02e7 commit 3d3626a

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/github/GitHubWorkflowRunSyncService.java

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Collections;
2323
import java.util.HashSet;
2424
import java.util.List;
25+
import java.util.Optional;
2526
import java.util.Set;
2627
import lombok.RequiredArgsConstructor;
2728
import lombok.extern.log4j.Log4j2;
@@ -213,26 +214,40 @@ private void processRunForHeliosDeployment(GHWorkflowRun workflowRun) throws IOE
213214
mapWorkflowRunStatus(workflowRun.getStatus(), workflowRun.getConclusion());
214215
log.debug("Mapped status {} to {}", workflowRun.getStatus(), mappedStatus);
215216

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());
235249
}
250+
236251
// Update the deployment status
237252
heliosDeployment.setStatus(mappedStatus);
238253

0 commit comments

Comments
 (0)