Skip to content

Commit

Permalink
Changelog. Find different kinds of release notes
Browse files Browse the repository at this point in the history
The current script contains JetBrains/compose-multiplatform-core#1821 because it started with #, not with ##

# Testing
```
kotlin changelog.main.kts v1.8.0-alpha02..v1.8.0+dev2047
```
Doesn't contain JetBrains/compose-multiplatform-core#1821

# Release Notes
N/A
  • Loading branch information
igordmn committed Feb 6, 2025
1 parent ef905d8 commit 06f34a0
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions tools/changelog.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -364,20 +364,26 @@ fun String.removeLinks(): String = replace(Regex("\\[([^)]*)\\]\\([^\\]]*\\)"),
* Extract by format https://github.com/JetBrains/compose-multiplatform/blob/master/.github/PULL_REQUEST_TEMPLATE.md?plain=1
*/
fun GitHubPullEntry.extractReleaseNotes(): ReleaseNotes? {
// extract body inside "## Release Notes"
val relNoteBody = run {
val after = body?.substringAfter("## Release Notes", "")?.ifBlank { null }
?: body?.substringAfter("## Release notes", "")?.ifBlank { null } ?: body?.substringAfter(
"## RelNote",
""
)?.ifBlank { null }

val before = after?.substringBefore("\n## ", "")?.ifBlank { null } ?: after?.substringBefore("\n# ", "")
?.ifBlank { null } ?: after

before?.trim()
fun String?.substringBetween(begin: String, end: String): String? {
val after = this?.substringAfter(begin, "")?.ifBlank { null }
return after?.substringBefore(end, "")?.ifBlank { null } ?: after
}

// extract body inside "# Release Notes"
val relNoteBody = body
?.replace("# Release notes", "# Release Notes", ignoreCase = true)
?.replace("#Release notes", "# Release Notes", ignoreCase = true)
?.replace("# RelNote", "# Release Notes", ignoreCase = true)
?.run {
substringBetween("# Release Notes", "\n# ")
?: substringBetween("## Release Notes", "\n## ")
?: substringBetween("### Release Notes", "\n### ")
?: substringBetween("## Release Notes", "\n# ")
?: substringBetween("### Release Notes", "\n## ")
?: substringBetween("### Release Notes", "\n# ")
}
?.trim()

if (relNoteBody == null) return null
if (relNoteBody.trim().lowercase() == "n/a") return ReleaseNotes.NA

Expand All @@ -388,9 +394,9 @@ fun GitHubPullEntry.extractReleaseNotes(): ReleaseNotes? {
var shouldPadLines = false

for (line in relNoteBody.split("\n")) {
// parse "### Section - Subsection"
if (line.startsWith("### ")) {
val s = line.removePrefix("### ")
// parse "## Section - Subsection"
if (line.trim().startsWith("#")) {
val s = line.trimStart { it == '#' || it.isWhitespace() }
section = s.substringBefore("-", "").trim().normalizeSectionName().ifEmpty { null }
subsection = s.substringAfter("-", "").trim().normalizeSubsectionName().ifEmpty { null }
isFirstLine = true
Expand Down

0 comments on commit 06f34a0

Please sign in to comment.