Skip to content

Commit

Permalink
Added --version=... CLI parameter for the getChangelog task #83
Browse files Browse the repository at this point in the history
  • Loading branch information
hsz committed Oct 18, 2022
1 parent 2d67450 commit 8c02fb0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class GetChangelogTaskTest : BaseTest() {
- bar
## [1.0.1]
Release with bugfix.
### Fixed
- bar
## [1.0.0]
That was a great release.
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 8c02fb0

Please sign in to comment.