Skip to content

Commit a29ec8b

Browse files
Append release notes at the end if no previous heading can be found (#14)
* Add Stubs * Add failing test * If no previous heading is found, paste release notes at the end
1 parent 16ee22b commit a29ec8b

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

app/Actions/PasteReleaseNotesBelowUnreleasedHeading.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ public function execute(Heading $unreleasedHeading, string $latestVersion, strin
5656
// Find the Heading of the previous Version
5757
$previousVersionHeading = $this->findPreviousVersionHeading->find($changelog, $previousVersion);
5858

59-
// Insert the newest Release Notes before the previous Release Heading
60-
$previousVersionHeading?->insertBefore($parsedReleaseNotes);
59+
if ($previousVersionHeading !== null) {
60+
// Insert the newest Release Notes before the previous Release Heading
61+
$previousVersionHeading->insertBefore($parsedReleaseNotes);
62+
} else {
63+
$changelog->lastChild()?->insertAfter($parsedReleaseNotes);
64+
}
6165

6266
return $changelog;
6367
}

tests/Feature/UpdateCommandTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,27 @@
145145
->assertExitCode(0);
146146
});
147147

148+
it('places given release notes in correct position even if changelog is empty besides an unreleased heading', function () {
149+
$this->artisan('update', [
150+
'--release-notes' => <<<MD
151+
### Added
152+
- New Feature A
153+
- New Feature B
154+
155+
### Changed
156+
- Update Feature C
157+
158+
### Removes
159+
- Remove Feature D
160+
MD,
161+
'--latest-version' => 'v1.0.0',
162+
'--path-to-changelog' => __DIR__ . '/../Stubs/base-changelog-empty-with-unreleased.md',
163+
'--release-date' => '2021-02-01',
164+
])
165+
->expectsOutput(file_get_contents(__DIR__ . '/../Stubs/expected-changelog-empty-with-unreleased.md'))
166+
->assertExitCode(0);
167+
});
168+
148169
it('uses compare-url-target option in unreleased heading url', function () {
149170
$this->artisan('update', [
150171
'--release-notes' => <<<MD
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased](https://github.com/org/repo/compare/v0.1.0...HEAD)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
## [v1.0.0](https://github.com/org/repo/compare/v0.1.0...v1.0.0) - 2021-02-01
11+
12+
### Added
13+
14+
- New Feature A
15+
- New Feature B
16+
17+
### Changed
18+
19+
- Update Feature C
20+
21+
### Removes
22+
23+
- Remove Feature D

0 commit comments

Comments
 (0)