mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-04 12:49:39 +02:00
Notify user about results of manually executed health check (#2044)
When manually starting health checks, the user should always receive a notification about the status, whether successful or not.
This commit is contained in:
@@ -227,22 +227,28 @@ final class HealthChecker {
|
||||
}
|
||||
|
||||
private void notifyCurrentUser(Repository repository, HealthCheckResult result) {
|
||||
if (!(repository.isHealthy() && result.isHealthy())) {
|
||||
String currentUser = SecurityUtils.getSubject().getPrincipal().toString();
|
||||
if (!scmConfiguration.getEmergencyContacts().contains(currentUser)) {
|
||||
notificationSender.send(getHealthCheckFailedNotification(repository));
|
||||
}
|
||||
if (repository.isHealthy() && result.isHealthy()) {
|
||||
notificationSender.send(getHealthCheckSuccessNotification(repository));
|
||||
} else {
|
||||
notificationSender.send(getHealthCheckFailedNotification(repository));
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyEmergencyContacts(Repository repository) {
|
||||
String currentUser = SecurityUtils.getSubject().getPrincipal().toString();
|
||||
Set<String> emergencyContacts = scmConfiguration.getEmergencyContacts();
|
||||
for (String user : emergencyContacts) {
|
||||
notificationSender.send(getHealthCheckFailedNotification(repository), user);
|
||||
if (!user.equals(currentUser)) {
|
||||
notificationSender.send(getHealthCheckFailedNotification(repository), user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Notification getHealthCheckFailedNotification(Repository repository) {
|
||||
return new Notification(Type.ERROR, "/repo/" + repository.getNamespaceAndName() + "/settings/general", "healthCheckFailed");
|
||||
}
|
||||
|
||||
private Notification getHealthCheckSuccessNotification(Repository repository) {
|
||||
return new Notification(Type.SUCCESS, "/repo/" + repository.getNamespaceAndName() + "/settings/general", "healthCheckSuccess");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user