Skip to content

Commit 6e4a1e4

Browse files
Add --hide-release-date option (#39)
* Add hideDate to CreateNewReleaseHeadingWithCompareUrl * Add hideDate to CreateNewReleaseHeading * Add hideReleaseDate option to command and pass it around * Add Test for UpdateCommand * Update README.md
1 parent d7d307c commit 6e4a1e4

12 files changed

+243
-31
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,17 @@ Optional. Will output values for `UNRELEASED_COMPARE_URL` and `RELEASE_COMPARE_U
7474
### `--heading-text`
7575
Optional (Defaults to value of `--latest-version`). The text value used in the heading that is created for the new release.
7676

77-
### `--parse-release-notes`
78-
Optional. Tell the CLI explicitly to use the content between an "Unreleased Heading" and the previous version heading as release notes. The value from `--release-notes` will be ignored.
79-
8077
```md
8178
## heading-text - 2021-02-01
8279
## [heading-text](https://github.com/org/repo/compare/v0.1.0...v1.0.0) - 2021-02-01
8380
```
8481

82+
### `--parse-release-notes`
83+
Optional. Tell the CLI explicitly to use the content between an "Unreleased Heading" and the previous version heading as release notes. The value from `--release-notes` will be ignored.
84+
85+
### `--hide-release-date`
86+
Optional. Don't add the release date to the release heading.
87+
8588
## Expected Changelog Formats
8689

8790
The CLI does its best to place the given release notes in the right place.

app/Actions/AddReleaseNotesToChangelogAction.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(
2626
/**
2727
* @throws Throwable
2828
*/
29-
public function execute(string $originalChangelog, string $latestVersion, string $headingText, ?string $releaseNotes, string $releaseDate, string $compareUrlTargetRevision): RenderedContentInterface
29+
public function execute(string $originalChangelog, string $latestVersion, string $headingText, ?string $releaseNotes, string $releaseDate, string $compareUrlTargetRevision, bool $hideDate = false): RenderedContentInterface
3030
{
3131
$changelog = $this->markdown->parse($originalChangelog);
3232

@@ -42,14 +42,16 @@ public function execute(string $originalChangelog, string $latestVersion, string
4242
releaseDate: $releaseDate,
4343
releaseNotes: $releaseNotes,
4444
changelog: $changelog,
45-
compareUrlTargetRevision: $compareUrlTargetRevision
45+
compareUrlTargetRevision: $compareUrlTargetRevision,
46+
hideDate: $hideDate
4647
);
4748
} else {
4849
$changelog = $this->addNewReleaseToChangelog->execute(
4950
changelog: $changelog,
5051
headingText: $headingText,
5152
releaseDate: $releaseDate,
52-
releaseNotes: $releaseNotes
53+
releaseNotes: $releaseNotes,
54+
hideDate: $hideDate,
5355
);
5456
}
5557

app/Actions/PlaceReleaseNotesAtTheTopAction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public function __construct(
2222
/**
2323
* @throws Throwable
2424
*/
25-
public function execute(Document $changelog, string $headingText, string $releaseDate, ?string $releaseNotes): Document
25+
public function execute(Document $changelog, string $headingText, string $releaseDate, ?string $releaseNotes, bool $hideDate = false): Document
2626
{
2727
throw_if(empty($releaseNotes), ReleaseNotesNotProvidedException::class);
2828

29-
$newReleaseHeading = $this->createNewReleaseHeading->create($headingText, $releaseDate);
29+
$newReleaseHeading = $this->createNewReleaseHeading->create($headingText, $releaseDate, $hideDate);
3030

3131
// Find the Heading of the previous Version
3232
$previousVersionHeading = $this->findFirstSecondLevelHeading->find($changelog);

app/Actions/PlaceReleaseNotesBelowUnreleasedHeadingAction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(
2929
/**
3030
* @throws Throwable
3131
*/
32-
public function execute(Heading $unreleasedHeading, string $latestVersion, string $headingText, string $releaseDate, ?string $releaseNotes, Document $changelog, string $compareUrlTargetRevision): Document
32+
public function execute(Heading $unreleasedHeading, string $latestVersion, string $headingText, string $releaseDate, ?string $releaseNotes, Document $changelog, string $compareUrlTargetRevision, bool $hideDate = false): Document
3333
{
3434
$previousVersion = $this->getPreviousVersionFromUnreleasedHeading($unreleasedHeading);
3535
$repositoryUrl = $this->getRepositoryUrlFromUnreleasedHeading($unreleasedHeading);
@@ -40,7 +40,7 @@ public function execute(Heading $unreleasedHeading, string $latestVersion, strin
4040
$this->gitHubActionsOutput->add('UNRELEASED_COMPARE_URL', $updatedUrl);
4141

4242
// Create new Heading containing the new version number
43-
$newReleaseHeading = $this->createNewReleaseHeading->create($repositoryUrl, $previousVersion, $latestVersion, $headingText, $releaseDate);
43+
$newReleaseHeading = $this->createNewReleaseHeading->create($repositoryUrl, $previousVersion, $latestVersion, $headingText, $releaseDate, $hideDate);
4444

4545
if (empty($releaseNotes)) {
4646
// If no Release Notes have been passed, add the new Release Heading below the updated Unreleased Heading.

app/Commands/UpdateCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class UpdateCommand extends Command
2525
{--path-to-changelog=CHANGELOG.md : Path to changelog markdown file to be updated.}
2626
{--compare-url-target-revision=HEAD : Target revision used in the compare URL of possible "Unreleased" heading.}
2727
{--github-actions-output : Display GitHub Actions related output}
28+
{--hide-release-date : Hide release date in the new release heading.}
2829
{-w\--write : Write changes to file}
2930
';
3031

@@ -41,6 +42,7 @@ public function handle(AddReleaseNotesToChangelogAction $addReleaseNotesToChange
4142
$pathToChangelog = $this->option('path-to-changelog');
4243
$compareUrlTargetRevision = $this->option('compare-url-target-revision');
4344
$headingText = $this->option('heading-text');
45+
$hideDate = $this->option('hide-release-date');
4446

4547
Assert::stringNotEmpty($latestVersion, 'No latest-version option provided. Abort.');
4648
Assert::fileExists($pathToChangelog, 'CHANGELOG file not found. Abort.');
@@ -62,7 +64,8 @@ public function handle(AddReleaseNotesToChangelogAction $addReleaseNotesToChange
6264
headingText: $headingText,
6365
releaseNotes: $releaseNotes,
6466
releaseDate: $releaseDate,
65-
compareUrlTargetRevision: $compareUrlTargetRevision
67+
compareUrlTargetRevision: $compareUrlTargetRevision,
68+
hideDate: $hideDate,
6669
);
6770
$this->info($updatedChangelog->getContent());
6871

app/CreateNewReleaseHeading.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ public function __construct(private readonly ExtractPermalinkFragmentFromHeading
1414
{
1515
}
1616

17-
public function create(string $text, string $releaseDate): Heading
17+
public function create(string $text, string $releaseDate, bool $hideDate = false): Heading
1818
{
19-
return tap(new Heading(2), function (Heading $heading) use ($text, $releaseDate) {
19+
return tap(new Heading(2), function (Heading $heading) use ($hideDate, $text, $releaseDate) {
2020
$heading->appendChild(new Text($text));
21-
$heading->appendChild(new Text(" - {$releaseDate}"));
21+
22+
if ($hideDate === false) {
23+
$heading->appendChild(new Text(" - {$releaseDate}"));
24+
}
2225

2326
$this->extractPermalinkFragmentFromHeading->execute($heading);
2427
});

app/CreateNewReleaseHeadingWithCompareUrl.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ public function __construct(
1919
) {
2020
}
2121

22-
public function create(string $repositoryUrl, string $previousVersion, string $latestVersion, string $headingText, string $releaseDate): Heading
22+
public function create(string $repositoryUrl, string $previousVersion, string $latestVersion, string $headingText, string $releaseDate, bool $hideDate = false): Heading
2323
{
2424
$url = $this->generateCompareUrl->generate($repositoryUrl, $previousVersion, $latestVersion);
2525

2626
$this->gitHubActionsOutput->add('RELEASE_COMPARE_URL', $url);
2727

28-
return tap(new Heading(2), function (Heading $heading) use ($headingText, $url, $releaseDate) {
28+
return tap(new Heading(2), function (Heading $heading) use ($hideDate, $headingText, $url, $releaseDate) {
2929
$heading->appendChild($this->createLinkNode($headingText, $url));
30-
$heading->appendChild($this->createDateNode($releaseDate));
30+
31+
if ($hideDate === false) {
32+
$heading->appendChild($this->createDateNode($releaseDate));
33+
}
3134

3235
$this->extractPermalinkFragmentFromHeading->execute($heading);
3336
});

tests/Feature/UpdateCommandTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,3 +443,47 @@
443443

444444
file_put_contents(__DIR__ . '/../Stubs/base-changelog.md', $originalContent);
445445
});
446+
447+
it('does not add date to release headings that have a compare url in it if --hide-release-date is passed', function () {
448+
$this->artisan(UpdateCommand::class, [
449+
'--release-notes' => <<<MD
450+
### Added
451+
- New Feature A
452+
- New Feature B
453+
454+
### Changed
455+
- Update Feature C
456+
457+
### Removes
458+
- Remove Feature D
459+
MD,
460+
'--latest-version' => 'v1.0.0',
461+
'--path-to-changelog' => __DIR__ . '/../Stubs/base-changelog.md',
462+
'--release-date' => '2021-02-01',
463+
'--hide-release-date' => true,
464+
])
465+
->expectsOutput(file_get_contents(__DIR__ . '/../Stubs/expected-changelog-without-date.md'))
466+
->assertSuccessful();
467+
});
468+
469+
it('does not add date to release heading if it does not contain a compare url and --hide-release-date option is passed', function () {
470+
$this->artisan(UpdateCommand::class, [
471+
'--release-notes' => <<<MD
472+
### Added
473+
- New Feature A
474+
- New Feature B
475+
476+
### Changed
477+
- Update Feature C
478+
479+
### Removes
480+
- Remove Feature D
481+
MD,
482+
'--latest-version' => 'v1.0.0',
483+
'--path-to-changelog' => __DIR__ . '/../Stubs/base-changelog-without-unreleased.md',
484+
'--release-date' => '2021-02-01',
485+
'--hide-release-date' => true,
486+
])
487+
->expectsOutput(file_get_contents(__DIR__ . '/../Stubs/expected-changelog-without-unreleased-without-date.md'))
488+
->assertSuccessful();
489+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased](https://github.com/org/repo/compare/v1.0.0...HEAD)
9+
10+
Please do not update the unreleased notes.
11+
12+
<!-- Content should be placed here -->
13+
## [v1.0.0](https://github.com/org/repo/compare/v0.1.0...v1.0.0)
14+
15+
### Added
16+
17+
- New Feature A
18+
- New Feature B
19+
20+
### Changed
21+
22+
- Update Feature C
23+
24+
### Removes
25+
26+
- Remove Feature D
27+
28+
## v0.1.0 - 2021-01-01
29+
30+
### Added
31+
32+
- Initial Release
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Changelog
2+
3+
## v1.0.0
4+
5+
### Added
6+
7+
- New Feature A
8+
- New Feature B
9+
10+
### Changed
11+
12+
- Update Feature C
13+
14+
### Removes
15+
16+
- Remove Feature D
17+
18+
## v0.1.0 - 2021-01-01
19+
20+
### Added
21+
22+
- Initial Release

0 commit comments

Comments
 (0)