override fun report()

in src/main/kotlin/org/jetbrains/teamcity/github/WebhookPeriodicalChecker.kt [74:117]


    override fun report(scope: HealthStatusScope, resultConsumer: HealthStatusItemConsumer) {
        if (!canReportItemsFor(scope)) return
        val gitRoots = HashSet<SVcsRoot>()
        Util.findSuitableRoots(scope) { gitRoots.add(it); true }

        val incorrectHooks = myWebHooksStorage.getIncorrectHooks()
        val incorrectHooksInfos = incorrectHooks.map { it.first }.toHashSet()

        val split = GitHubWebHookSuggestion.splitRoots(gitRoots)

        val myIncorrectHooksKeys = myIncorrectHooks.asMap().keys.toHashSet()
        val filtered = split.entrySet()
                .filter { it.key in myIncorrectHooksKeys || it.key in incorrectHooksInfos }
                .map { it.key to it.value }.toMap()

        for ((info, roots) in filtered) {
            val hook = incorrectHooks.firstOrNull { it.first == info }?.second ?: myWebHooksStorage.getHooks(info).firstOrNull()
            if (hook == null) {
                // Completely removed, even from our storage. Let's forget about it
                myIncorrectHooks.invalidate(info)
                continue
            }
            if (myWebHooksStorage.getHooks(info).any { it.status.good }) {
                // Installed new hook or fixed previous one
                myIncorrectHooks.invalidate(info)
                continue
            }
            val id = info.server + "#" + hook.id

            val reason = myIncorrectHooks.getIfPresent(info) ?: "Unknown reason"

            val item = HealthStatusItem("GitHubWebHook.I.$id", CATEGORY, mapOf(
                    "GitHubInfo" to info,
                    "HookInfo" to hook,
                    "Projects" to Util.getProjects(roots),
                    "Reason" to reason
            ))

            for (it in roots) {
                resultConsumer.consumeForVcsRoot(it, item)
                it.usagesInConfigurations.forEach { resultConsumer.consumeForBuildType(it, item) }
            }
        }
    }