Skip to content

Commit 451c3be

Browse files
authored
Changelog. Change links format (#5234)
Fixes https://youtrack.jetbrains.com/issue/CMP-7606/Changelog.-Change-link-format # Testing ``` kotlin changelog.main.kts v1.8.0-alpha02..v1.8.0+dev2047 ``` Formats correctly, links work # Release Notes N/A
1 parent d98a3d3 commit 451c3be

File tree

1 file changed

+4
-55
lines changed

1 file changed

+4
-55
lines changed

tools/changelog.main.kts

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ fun generateChangelog() {
193193
appendLine("### $subsection")
194194
appendLine()
195195
subsectionEntries.forEach {
196-
appendLine(it.format())
196+
appendLine(it.run { "$message [#$prNumber]($link)" })
197197
}
198198
appendLine()
199199
}
@@ -309,59 +309,6 @@ fun checkPr() {
309309
*/
310310
fun currentChangelogDate() = LocalDate.now().format(DateTimeFormatter.ofPattern("MMMM yyyy", Locale.ENGLISH))
311311

312-
/**
313-
* Formats:
314-
* - A new approach to implementation of `platformLayers`. Now extra layers (such as Dialogs and Popups) drawing is merged into a single screen size canvas.
315-
*
316-
* to:
317-
* - [A new approach to implementation of `platformLayers`](link). Now extra layers (such as Dialogs and Popups) drawing is merged into a single screen size canvas.
318-
*/
319-
fun ChangelogEntry.format(): String {
320-
return try {
321-
tryFormat()
322-
} catch (e: Exception) {
323-
throw RuntimeException("Formatting error of ChangelogEntry. Message:\n$message", e)
324-
}
325-
}
326-
327-
fun ChangelogEntry.tryFormat(): String {
328-
return if (link != null) {
329-
val prefixRegex = "^[-\\s]*" // "- "
330-
val tagRegex1 = "\\(.*\\)\\s*" // "(something) "
331-
val tagRegex2 = "\\[.*\\]\\s*" // "[something] "
332-
val tagRegex3 = "_.*_\\s*" // "_something_ "
333-
val linkStartIndex = maxOf(
334-
message.endIndexOfFirstGroup(Regex("($prefixRegex).*"))?.plus(1) ?: 0,
335-
message.endIndexOfFirstGroup(Regex("($prefixRegex$tagRegex1).*"))?.plus(1) ?: 0,
336-
message.endIndexOfFirstGroup(Regex("($prefixRegex$tagRegex2).*"))?.plus(1) ?: 0,
337-
message.endIndexOfFirstGroup(Regex("($prefixRegex$tagRegex3).*"))?.plus(1) ?: 0,
338-
)
339-
val linkLastIndex = message.indexOfAny(listOf(". ", " ("), linkStartIndex).ifNegative { message.length }
340-
341-
val beforeLink = message.substring(0, linkStartIndex)
342-
val inLink = message.substring(linkStartIndex, linkLastIndex).removeLinks()
343-
val afterLink = message.substring(linkLastIndex, message.length)
344-
345-
"$beforeLink[$inLink]($link)$afterLink"
346-
} else {
347-
message
348-
}
349-
}
350-
351-
fun Int.ifNegative(value: () -> Int): Int = if (this < 0) value() else this
352-
353-
fun String.endIndexOfFirstGroup(regex: Regex): Int? =
354-
regex.find(this)?.groups?.toList()?.getOrNull(1)?.range?.endInclusive
355-
356-
/**
357-
* Converts:
358-
* Message (title)[some link], message
359-
*
360-
* to:
361-
* Message title, message
362-
*/
363-
fun String.removeLinks(): String = replace(Regex("\\[([^)]*)\\]\\([^\\]]*\\)"), "$1")
364-
365312
/**
366313
* Extract by format https://github.com/JetBrains/compose-multiplatform/blob/master/.github/PULL_REQUEST_TEMPLATE.md?plain=1
367314
*/
@@ -421,6 +368,7 @@ fun GitHubPullEntry.extractReleaseNotes(): ReleaseNotes? {
421368
lineFixed,
422369
section,
423370
subsection,
371+
number,
424372
htmlUrl.takeIf { isTopLevel }
425373
)
426374
)
@@ -448,7 +396,7 @@ fun entriesForRepo(repo: String, firstCommit: String, lastCommit: String): List<
448396
): List<ChangelogEntry> {
449397
return if (pullRequest != null) {
450398
pullRequest.extractReleaseNotes()?.entries ?:
451-
listOf(ChangelogEntry("- ${pullRequest.title}", null, null, pullRequest.htmlUrl))
399+
listOf(ChangelogEntry("- ${pullRequest.title}", null, null, pullRequest.number, pullRequest.htmlUrl))
452400
} else {
453401
listOf()
454402
}
@@ -544,6 +492,7 @@ data class ChangelogEntry(
544492
val message: String,
545493
val section: String?,
546494
val subsection: String?,
495+
val prNumber: Int,
547496
val link: String?,
548497
)
549498

0 commit comments

Comments
 (0)