From b6a8ad6b9cfebe9846407317be7672704a9ef530 Mon Sep 17 00:00:00 2001 From: antoinbo <87284775+antoinbo@users.noreply.github.com> Date: Fri, 22 Nov 2024 22:16:45 +0100 Subject: [PATCH] Move GHAM notification logic outside recursion Signed-off-by: antoinbo <87284775+antoinbo@users.noreply.github.com> --- .../tasks/GitHubAdvisoryMirrorTask.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/dependencytrack/tasks/GitHubAdvisoryMirrorTask.java b/src/main/java/org/dependencytrack/tasks/GitHubAdvisoryMirrorTask.java index 7bc23cea5c..d90ee8ce83 100644 --- a/src/main/java/org/dependencytrack/tasks/GitHubAdvisoryMirrorTask.java +++ b/src/main/java/org/dependencytrack/tasks/GitHubAdvisoryMirrorTask.java @@ -112,6 +112,24 @@ public void inform(final Event e) { final long end = System.currentTimeMillis(); LOGGER.info("GitHub Advisory mirroring complete"); LOGGER.info("Time spent (total): " + (end - start) + "ms"); + + if (mirroredWithoutErrors) { + Notification.dispatch(new Notification() + .scope(NotificationScope.SYSTEM) + .group(NotificationGroup.DATASOURCE_MIRRORING) + .title(NotificationConstants.Title.GITHUB_ADVISORY_MIRROR) + .content("Mirroring of GitHub Advisories completed successfully") + .level(NotificationLevel.INFORMATIONAL) + ); + } else { + Notification.dispatch(new Notification() + .scope(NotificationScope.SYSTEM) + .group(NotificationGroup.DATASOURCE_MIRRORING) + .title(NotificationConstants.Title.GITHUB_ADVISORY_MIRROR) + .content("An error occurred mirroring the contents of GitHub Advisories. Check log for details.") + .level(NotificationLevel.ERROR) + ); + } } else { LOGGER.warn("GitHub Advisory mirroring is enabled, but no personal access token is configured. Skipping."); } @@ -159,24 +177,6 @@ private void retrieveAdvisories(final String advisoriesEndCursor) throws IOExcep retrieveAdvisories(pageableList.getEndCursor()); } } - - if (mirroredWithoutErrors) { - Notification.dispatch(new Notification() - .scope(NotificationScope.SYSTEM) - .group(NotificationGroup.DATASOURCE_MIRRORING) - .title(NotificationConstants.Title.GITHUB_ADVISORY_MIRROR) - .content("Mirroring of GitHub Advisories completed successfully") - .level(NotificationLevel.INFORMATIONAL) - ); - } else { - Notification.dispatch(new Notification() - .scope(NotificationScope.SYSTEM) - .group(NotificationGroup.DATASOURCE_MIRRORING) - .title(NotificationConstants.Title.GITHUB_ADVISORY_MIRROR) - .content("An error occurred mirroring the contents of GitHub Advisories. Check log for details.") - .level(NotificationLevel.ERROR) - ); - } } }