Skip to content

Commit

Permalink
Fix comparison of versions containing hyphens, possibly fixes JetBrai…
Browse files Browse the repository at this point in the history
  • Loading branch information
PHPirates committed Mar 22, 2024
1 parent d1c920c commit 97536d0
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/org/jetbrains/changelog/Version.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 97536d0

Please sign in to comment.