From 8c02fb07d5e2b38e862ef0129e770bc61a98ee4a Mon Sep 17 00:00:00 2001 From: Jakub Chrzanowski Date: Tue, 18 Oct 2022 19:29:33 +0200 Subject: [PATCH] Added `--version=...` CLI parameter for the `getChangelog` task #83 --- CHANGELOG.md | 1 + README.md | 14 +++++++---- .../changelog/tasks/GetChangelogTask.kt | 7 +++++- .../changelog/tasks/GetChangelogTaskTest.kt | 23 +++++++++++++++++++ 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 921b5e2..421cb3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Introduce changelog `description` and changelog section summary [#127](../../issues/127) - Introduce changelog `preTitle` and `title` changelog properties - Ensure patched changelog ends with a newline [#126](../../issues/126) +- Added the `--version=...` CLI parameter for the `getChangelog` task [#83](../../issues/83) ### Changed - Upgrade minimal required Gradle version to `6.8` diff --git a/README.md b/README.md index ffd474f..75bf916 100644 --- a/README.md +++ b/README.md @@ -165,12 +165,15 @@ The plugin introduces the following tasks: ### `getChangelog` Retrieves changelog for the specified version. + #### Options -| Option | Description | -|----------------|----------------------------------------------------| -| `--no-header` | Skips the first version header line in the output. | -| `--no-summary` | Skips the summary section in the output. | -| `--unreleased` | Returns Unreleased change notes. | +| Option | Type | Description | +|----------------|-----------|----------------------------------------------------| +| `--no-header` | `Boolean` | Skips the first version header line in the output. | +| `--no-summary` | `Boolean` | Skips the summary section in the output. | +| `--unreleased` | `Boolean` | Returns Unreleased change notes. | +| `--version` | `String` | Returns change notes for the specified version. | + #### Examples ```shell $ ./gradlew getChangelog --console=plain -q --no-header --no-summary @@ -184,6 +187,7 @@ $ ./gradlew getChangelog --console=plain -q --no-header --no-summary ### `initializeChangelog` Creates new changelog file with Unreleased section and empty groups. + #### Examples ```shell $ ./gradlew initializeChangelog diff --git a/src/main/kotlin/org/jetbrains/changelog/tasks/GetChangelogTask.kt b/src/main/kotlin/org/jetbrains/changelog/tasks/GetChangelogTask.kt index 2ff5915..a9b0035 100644 --- a/src/main/kotlin/org/jetbrains/changelog/tasks/GetChangelogTask.kt +++ b/src/main/kotlin/org/jetbrains/changelog/tasks/GetChangelogTask.kt @@ -22,6 +22,11 @@ abstract class GetChangelogTask : DefaultTask() { @Option(option = "no-summary", description = "Omits summary section") var noSummary = false + @get:Input + @get:Optional + @Option(option = "version", description = "Returns change notes for the specified version") + var cliVersion = null as String? + @get:Input @Option(option = "unreleased", description = "Returns Unreleased change notes") var unreleased = false @@ -57,7 +62,7 @@ abstract class GetChangelogTask : DefaultTask() { headerParserRegex.get(), itemPrefix.get(), ).let { - val version = when (unreleased) { + val version = cliVersion ?: when (unreleased) { true -> unreleasedTerm false -> version }.get() diff --git a/src/test/kotlin/org/jetbrains/changelog/tasks/GetChangelogTaskTest.kt b/src/test/kotlin/org/jetbrains/changelog/tasks/GetChangelogTaskTest.kt index e6f2e10..602449e 100644 --- a/src/test/kotlin/org/jetbrains/changelog/tasks/GetChangelogTaskTest.kt +++ b/src/test/kotlin/org/jetbrains/changelog/tasks/GetChangelogTaskTest.kt @@ -21,6 +21,12 @@ class GetChangelogTaskTest : BaseTest() { - bar + ## [1.0.1] + Release with bugfix. + + ### Fixed + - bar + ## [1.0.0] That was a great release. @@ -74,6 +80,23 @@ class GetChangelogTaskTest : BaseTest() { ) } + @Test + fun `returns change notes for the version specified with CLI`() { + val result = runTask(GET_CHANGELOG_TASK_NAME, "--quiet", "--version=1.0.1") + + //language=markdown + assertEquals( + """ + ## [1.0.1] + Release with bugfix. + + ### Fixed + - bar + """.trimIndent(), + result.output.trim() + ) + } + @Test fun `returns change notes without header for the version specified with extension`() { val result = runTask(GET_CHANGELOG_TASK_NAME, "--quiet", "--no-header")