Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add versionPrefix to allow setting the version prefix to compare tags #140

Merged
merged 2 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`. |
Expand Down
9 changes: 6 additions & 3 deletions src/main/kotlin/org/jetbrains/changelog/ChangelogPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class ChangelogPlugin : Plugin<Project> {
toAbsolutePath().toString()
}
})
versionPrefix.convention(project.provider { "v" })

version.convention(
project.provider {
project.version.toString().takeIf { it != Project.DEFAULT_VERSION }
Expand Down Expand Up @@ -78,15 +80,16 @@ class ChangelogPlugin : Plugin<Project> {
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"
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>

/**
* Current version. By default, project's version is used.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MissingVersionException> {
extension.getUnreleased().also {
println("it = ${it}")
}
}
}

@Test
fun `applies custom header patcher`() {
buildFile =
Expand Down