diff --git a/CHANGELOG.md b/CHANGELOG.md index cd1c82b..2a6b404 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ ## [Unreleased] ### Added -- Add `--no-empty-sections` flag to `getChangelog` task. [#167](../../issues/167) +- `versionPrefix` to allow setting the version prefix to compare tags [#139](../../issues/139) +- `--no-empty-sections` flag to `getChangelog` task [#167](../../issues/167) ### Fixed - No-longer discard all but the last paragraph in list items [#133](../../issues/133) [#147](../../issues/147) diff --git a/README.md b/README.md index 45b20b3..b22bedc 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,7 @@ Plugin can be configured with the following properties set in the `changelog {}` | Property | Type | Default value | Description | |-------------------------|--------------------------------|----------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------| +| `versionPrefix` | `String` | `v` | Version prefix used to compare tags. | | `version` | `String` | `project.version` | Current version. By default, project's version is used. | | `path` | `String` | `file("CHANGELOG.md").cannonicalPath` | Path to the changelog file. | | `preTitle` | `String?` | `null` | Optional content placed before the `title`. | diff --git a/src/main/kotlin/org/jetbrains/changelog/ChangelogPlugin.kt b/src/main/kotlin/org/jetbrains/changelog/ChangelogPlugin.kt index 5ee8dcb..2ada3e0 100644 --- a/src/main/kotlin/org/jetbrains/changelog/ChangelogPlugin.kt +++ b/src/main/kotlin/org/jetbrains/changelog/ChangelogPlugin.kt @@ -43,6 +43,8 @@ class ChangelogPlugin : Plugin { toAbsolutePath().toString() } }) + versionPrefix.convention(project.provider { "v" }) + version.convention( project.provider { project.version.toString().takeIf { it != Project.DEFAULT_VERSION } @@ -78,15 +80,16 @@ class ChangelogPlugin : Plugin { repositoryUrl.map { it.removeSuffix("/") } sectionUrlBuilder.convention( ChangelogSectionUrlBuilder { repositoryUrl, currentVersion, previousVersion, isUnreleased -> + val prefix = versionPrefix.get() repositoryUrl + when { isUnreleased -> when (previousVersion) { null -> "/commits" - else -> "/compare/v$previousVersion...HEAD" + else -> "/compare/$prefix$previousVersion...HEAD" } - previousVersion == null -> "/commits/v$currentVersion" + previousVersion == null -> "/commits/$prefix$currentVersion" - else -> "/compare/v$previousVersion...v$currentVersion" + else -> "/compare/$prefix$previousVersion...$prefix$currentVersion" } } ) diff --git a/src/main/kotlin/org/jetbrains/changelog/ChangelogPluginExtension.kt b/src/main/kotlin/org/jetbrains/changelog/ChangelogPluginExtension.kt index 0d87000..0dfaa8a 100644 --- a/src/main/kotlin/org/jetbrains/changelog/ChangelogPluginExtension.kt +++ b/src/main/kotlin/org/jetbrains/changelog/ChangelogPluginExtension.kt @@ -13,6 +13,14 @@ import java.util.regex.Pattern abstract class ChangelogPluginExtension { + /** + * Version prefix used to compare tags. + * + * Default value: `v` + */ + @get:Optional + abstract val versionPrefix: Property + /** * Current version. By default, project's version is used. * diff --git a/src/test/kotlin/org/jetbrains/changelog/tasks/PatchChangelogTaskTest.kt b/src/test/kotlin/org/jetbrains/changelog/tasks/PatchChangelogTaskTest.kt index 2c77f7f..e8b011c 100644 --- a/src/test/kotlin/org/jetbrains/changelog/tasks/PatchChangelogTaskTest.kt +++ b/src/test/kotlin/org/jetbrains/changelog/tasks/PatchChangelogTaskTest.kt @@ -117,6 +117,45 @@ class PatchChangelogTaskTest : BaseTest() { } } + @Test + fun `patches Unreleased version with custom version prefix to the current one`() { + buildFile = + """ + plugins { + id 'org.jetbrains.changelog' + } + changelog { + versionPrefix = "w" + version = "$version" + keepUnreleasedSection = false + repositoryUrl = "https://github.com/JetBrains/gradle-changelog-plugin" + } + """.trimIndent() + + project.evaluate() + runTask(PATCH_CHANGELOG_TASK_NAME) + + assertMarkdown( + """ + ## [1.0.0] - $date + Fancy release. + + ### Added + - foo + + [1.0.0]: https://github.com/JetBrains/gradle-changelog-plugin/commits/w1.0.0 + + """.trimIndent(), + extension.renderItem(extension.get(version)) + ) + + assertFailsWith { + extension.getUnreleased().also { + println("it = ${it}") + } + } + } + @Test fun `applies custom header patcher`() { buildFile =