From 56cb18b2d3c820ea57d6ab9b7f968bebbad1b1e3 Mon Sep 17 00:00:00 2001 From: Thomas Schouten Date: Fri, 22 Mar 2024 20:17:40 +0100 Subject: [PATCH] Fix comparison of versions containing hyphens, possibly fixes #171 --- .../kotlin/org/jetbrains/changelog/Version.kt | 4 +- .../changelog/tasks/PatchChangelogTaskTest.kt | 72 +++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/jetbrains/changelog/Version.kt b/src/main/kotlin/org/jetbrains/changelog/Version.kt index 6948638..0618c2d 100644 --- a/src/main/kotlin/org/jetbrains/changelog/Version.kt +++ b/src/main/kotlin/org/jetbrains/changelog/Version.kt @@ -28,8 +28,8 @@ class Version( .or { patch - other.patch } .or { when { - version.contains('-') -> -1 - other.version.contains('-') -> 1 + version.contains('-') && other.version.contains('-').not() -> -1 + other.version.contains('-') && version.contains('-').not() -> 1 else -> 0 } } diff --git a/src/test/kotlin/org/jetbrains/changelog/tasks/PatchChangelogTaskTest.kt b/src/test/kotlin/org/jetbrains/changelog/tasks/PatchChangelogTaskTest.kt index a98622c..caee78f 100644 --- a/src/test/kotlin/org/jetbrains/changelog/tasks/PatchChangelogTaskTest.kt +++ b/src/test/kotlin/org/jetbrains/changelog/tasks/PatchChangelogTaskTest.kt @@ -630,6 +630,78 @@ class PatchChangelogTaskTest : BaseTest() { assertTrue(changelog.endsWith(lineSeparator)) } + @Test + fun `test sorting version links`() { + buildFile = + """ + plugins { + id 'org.jetbrains.changelog' + } + changelog { + version = "0.9.5-alpha.3" + repositoryUrl = "https://github.com/JetBrains/gradle-changelog-plugin" + } + """.trimIndent() + + changelog = + """ + # Changelog + + ## [Unreleased] + + ### Added + + ### Fixed + + ## [0.9.5-alpha.3] - 2024-02-11 + ## [0.9.5-alpha.2] - 2024-02-10 + ## [0.9.5-alpha.1] - 2024-02-06 + ## [0.9.4] - 2024-02-06 + ## [0.9.3] - 2024-01-16 + + [Unreleased]: https://github.com/JetBrains/gradle-changelog-plugin/compare/v0.9.5-alpha.6...HEAD + [0.9.5-alpha.2]: https://github.com/JetBrains/gradle-changelog-plugin/compare/v0.9.5-alpha.1...v0.9.5-alpha.2 + [0.9.5-alpha.1]: https://github.com/JetBrains/gradle-changelog-plugin/compare/v0.9.4...v0.9.5-alpha.1 + [0.9.5-alpha.3]: https://github.com/JetBrains/gradle-changelog-plugin/compare/v0.9.5-alpha.2...v0.9.5-alpha.3 + [0.9.4]: https://github.com/JetBrains/gradle-changelog-plugin/compare/v0.9.3...v0.9.4 + [0.9.3]: https://github.com/JetBrains/gradle-changelog-plugin/compare/v0.9.3...v0.9.2 + """.trimIndent() + + project.evaluate() + + runTask(PATCH_CHANGELOG_TASK_NAME) + + assertMarkdown( + """ + # Changelog + + ## [Unreleased] + + ### Added + + ### Fixed + + ## [0.9.5-alpha.3] - 2024-02-11 + + ## [0.9.5-alpha.2] - 2024-02-10 + + ## [0.9.5-alpha.1] - 2024-02-06 + + ## [0.9.4] - 2024-02-06 + + ## [0.9.3] - 2024-01-16 + + [Unreleased]: https://github.com/JetBrains/gradle-changelog-plugin/compare/v0.9.5-alpha.6...HEAD + [0.9.5-alpha.3]: https://github.com/JetBrains/gradle-changelog-plugin/compare/v0.9.5-alpha.2...v0.9.5-alpha.3 + [0.9.5-alpha.2]: https://github.com/JetBrains/gradle-changelog-plugin/compare/v0.9.5-alpha.1...v0.9.5-alpha.2 + [0.9.5-alpha.1]: https://github.com/JetBrains/gradle-changelog-plugin/compare/v0.9.4...v0.9.5-alpha.1 + [0.9.4]: https://github.com/JetBrains/gradle-changelog-plugin/compare/v0.9.3...v0.9.4 + [0.9.3]: https://github.com/JetBrains/gradle-changelog-plugin/compare/v0.9.3...v0.9.2 + """.trimIndent(), + extension.render() + ) + } + @Test fun `patched changelog contains an empty line at the end`() { runTask(PATCH_CHANGELOG_TASK_NAME)