diff --git a/src/main/kotlin/jetbrains/buildServer/notification/slackNotifier/healthReport/SlackBuildFeatureHealthReport.kt b/src/main/kotlin/jetbrains/buildServer/notification/slackNotifier/healthReport/SlackBuildFeatureHealthReport.kt index 6e5857d..da1ca16 100644 --- a/src/main/kotlin/jetbrains/buildServer/notification/slackNotifier/healthReport/SlackBuildFeatureHealthReport.kt +++ b/src/main/kotlin/jetbrains/buildServer/notification/slackNotifier/healthReport/SlackBuildFeatureHealthReport.kt @@ -68,27 +68,17 @@ class SlackBuildFeatureHealthReport( } override fun report(scope: HealthStatusScope, consumer: HealthStatusItemConsumer) { - val buildTypeItems = mutableListOf>() - val templateItems = mutableListOf>() - try { - for (buildType in scope.buildTypes) { - buildTypeItems.addAll(getStatusItems(buildType)) - } + for (buildType in scope.buildTypes) { + report(buildType, consumer) + } - for (buildTemplate in scope.buildTypeTemplates) { - templateItems.addAll(getStatusItems(buildTemplate)) - } - } catch (e: SlackResponseError) { - logger.error("Error while generating health report: ${e.message}") - return + for (buildTemplate in scope.buildTypeTemplates) { + report(buildTemplate, consumer) } - buildTypeItems.forEach { consumer.consumeForBuildType(it.first, it.second) } - templateItems.forEach { consumer.consumeForTemplate(it.first, it.second) } } - private fun getStatusItems(buildType: SBuildType): List> { + private fun report(buildType: SBuildType, consumer: HealthStatusItemConsumer) { val features = getFeatures(buildType) - val result = mutableListOf>() for (feature in features) { val statusItem = try { getHealthStatus(feature, buildType, "buildType") @@ -96,17 +86,18 @@ class SlackBuildFeatureHealthReport( null } catch (e: ExecutionException) { null + } catch (e: SlackResponseError) { + logger.error("Error while generating health report: ${e.message}") + null } if (statusItem != null) { - result.add(Pair(buildType, statusItem)) + consumer.consumeForBuildType(buildType, statusItem) } } - return result } - private fun getStatusItems(buildTemplate: BuildTypeTemplate): List> { + private fun report(buildTemplate: BuildTypeTemplate, consumer: HealthStatusItemConsumer) { val features = getFeatures(buildTemplate) - val result = mutableListOf>() for (feature in features) { val statusItem = try { getHealthStatus(feature, buildTemplate, "template") @@ -114,12 +105,14 @@ class SlackBuildFeatureHealthReport( null } catch (e: ExecutionException) { null + } catch (e: SlackResponseError) { + logger.error("Error while generating health report: ${e.message}") + null } if (statusItem != null) { - result.add(Pair(buildTemplate, statusItem)) + consumer.consumeForTemplate(buildTemplate, statusItem) } } - return result } private fun getFeatures(buildTypeSettings: BuildTypeSettings): List {