From 6fb015799c12a7abeac9e6970fb6bbd31a97cfa9 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 7 Mar 2024 12:03:36 +0100 Subject: show status at bottom --- src/main/kotlin/Main.kt | 95 ++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 53 deletions(-) diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 3025076..3a86372 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -61,11 +61,52 @@ fun main() { fun readPrs(prs: List, firstPr: Int, hideWhenError: Boolean, title: String, whatToDo: WhatToDo) { val categories = mutableListOf() val allChanges = mutableListOf() - findAllChanges(prs, allChanges, categories, firstPr, hideWhenError, whatToDo) + var errors = 0 + var done = 0 + // TODO find better solution for this sorting logic + val filtered = when (whatToDo) { + WhatToDo.NEXT_BETA -> prs.filter { it.mergedAt != null } + .map { it to it.mergedAt } + + WhatToDo.OPEN_PRS -> prs + .map { it to it.updatedAt } + + } + .map { it.first to Long.MAX_VALUE - Instant.parse(it.second).toEpochMilli() } + .sortedBy { it.second } + .map { it.first } + for (pr in filtered) { + val number = pr.number + val prLink = pr.htmlUrl + val body = pr.body + + val description = body?.split(System.lineSeparator()) ?: emptyList() + try { + allChanges.addAll(parseChanges(description, prLink, categories)) + done++ + } catch (t: Throwable) { + println("") + println("Error in #$number ($prLink)") + println(t.message) + errors++ + } + if (whatToDo == WhatToDo.NEXT_BETA) { + if (number == firstPr) break + } + } + println("") for (type in OutputType.entries) { print(categories, allChanges, type, title) } + println("") + println("Found $errors PRs with errors") + println("Loaded $done PRs correctly") + if (errors > 0) { + if (hideWhenError) { + exitProcess(-1) + } + } } enum class OutputType { @@ -126,58 +167,6 @@ fun getChangePrefix(name: String, outputType: OutputType): String = when (output } } -private fun findAllChanges( - prs: List, - changes: MutableList, - categories: MutableList, - firstPr: Int, - hideWhenError: Boolean, - whatToDo: WhatToDo, -) { - var errors = 0 - var done = 0 - // TODO find better solution for this sorting logic - val filtered = when (whatToDo) { - WhatToDo.NEXT_BETA -> prs.filter { it.mergedAt != null } - .map { it to it.mergedAt } - - WhatToDo.OPEN_PRS -> prs - .map { it to it.updatedAt } - - } - .map { it.first to Long.MAX_VALUE - Instant.parse(it.second).toEpochMilli() } - .sortedBy { it.second } - .map { it.first } - - for (pr in filtered) { - val number = pr.number - val prLink = pr.htmlUrl - val body = pr.body - - val description = body?.split(System.lineSeparator()) ?: emptyList() - try { - changes.addAll(parseChanges(description, prLink, categories)) - done++ - } catch (t: Throwable) { - println("") - println("Error in #$number ($prLink)") - println(t.message) - errors++ - } - if (whatToDo == WhatToDo.NEXT_BETA) { - if (number == firstPr) break - } - } - println("") - println("Found $errors PRs with errors") - println("Loaded $done PRs correctly") - if (errors > 0) { - if (hideWhenError) { - exitProcess(-1) - } - } -} - inline fun Pattern.matchMatcher(text: String, consumer: Matcher.() -> T) = matcher(text).let { if (it.matches()) consumer(it) else null } -- cgit