diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-03-07 12:03:36 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-03-07 12:03:36 +0100 |
commit | 6fb015799c12a7abeac9e6970fb6bbd31a97cfa9 (patch) | |
tree | f039fb1f5e0d51ce14a831621a65effe07c4457a | |
parent | 1274ae2a31ae8b152b13346fae11c8a9e64c01b1 (diff) | |
download | SkyHanniChangelogBuilder-6fb015799c12a7abeac9e6970fb6bbd31a97cfa9.tar.gz SkyHanniChangelogBuilder-6fb015799c12a7abeac9e6970fb6bbd31a97cfa9.tar.bz2 SkyHanniChangelogBuilder-6fb015799c12a7abeac9e6970fb6bbd31a97cfa9.zip |
show status at bottom
-rw-r--r-- | src/main/kotlin/Main.kt | 95 |
1 files 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<PullRequest>, firstPr: Int, hideWhenError: Boolean, title: String, whatToDo: WhatToDo) { val categories = mutableListOf<Category>() val allChanges = mutableListOf<Change>() - 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<PullRequest>, - changes: MutableList<Change>, - categories: MutableList<Category>, - 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 <T> Pattern.matchMatcher(text: String, consumer: Matcher.() -> T) = matcher(text).let { if (it.matches()) consumer(it) else null } |