Skip to content

Commit

Permalink
Add versionPrefix to allow setting the version prefix to compare ta…
Browse files Browse the repository at this point in the history
…gs (#140)

Co-authored-by: Jakub Chrzanowski <[email protected]>
  • Loading branch information
JavierSegoviaCordoba and hsz authored Jun 1, 2023
1 parent f3c3bdb commit 002bba2
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
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

0 comments on commit 002bba2

Please sign in to comment.