Skip to content

Commit 8b3c955

Browse files
Add --compare-url-target-revision option (#13)
* Update Dependencies * Add --compare-url-target-revision option * Add Stubs for Tests * Delete unused .gitkeep * Add Test * Use $compareUrlTarget * Update README
1 parent 2871517 commit 8b3c955

10 files changed

+393
-308
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ php changelog-updater update \
3838
--latest-version="v1.0.0" \
3939
--release-date="2021-08-07" \
4040
--path-to-changelog="CHANGELOG.md" \
41+
--compare-url-target-revision="1.x"
4142
--write
4243
```
4344

44-
`--release-date`, `--path-to-changelog` and `--write` are optional. Learn more about the options by running `php changelog-updater update --help`.
45+
`--release-date`, `--path-to-changelog`, `--compare-url-target-revision` and `--write` are optional. Learn more about the options by running `php changelog-updater update --help`.
4546

4647
### CLI Options
4748

@@ -59,6 +60,9 @@ Optional (Defaults to current date). The date the latest version has been releas
5960
### `--path-to-changelog`
6061
Optional (Defaults to `CHANGELOG.md`). Path to CHANGELOG.md file.
6162

63+
### `--compare-url-target-revision`
64+
Optional (Defaults to `HEAD`). If the changelog has a "Unreleased" heading, the value will be used together with the `--latest-version` value in the updated compare URL.
65+
6266
### `--write`
6367
Optional. Write the changes to `CHANGELOG.md` or to the value of `--path-to-changelog`.
6468

app/Actions/AddReleaseNotesToChangelog.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,21 @@ public function __construct(
3535
/**
3636
* @throws Throwable
3737
*/
38-
public function execute(string $originalChangelog, string $releaseNotes, string $latestVersion, string $releaseDate): RenderedContentInterface
38+
public function execute(string $originalChangelog, string $releaseNotes, string $latestVersion, string $releaseDate, string $compareUrlTargetRevision): RenderedContentInterface
3939
{
4040
$changelog = $this->markdownParser->parse($originalChangelog);
4141

4242
$unreleasedHeading = $this->findUnreleasedHeading->find($changelog);
4343

4444
if ($unreleasedHeading !== null) {
45-
$changelog = $this->pasteReleaseNotesBelowUnreleasedHeading->execute($unreleasedHeading, $latestVersion, $releaseDate, $releaseNotes, $changelog);
45+
$changelog = $this->pasteReleaseNotesBelowUnreleasedHeading->execute(
46+
unreleasedHeading: $unreleasedHeading,
47+
latestVersion: $latestVersion,
48+
releaseDate: $releaseDate,
49+
releaseNotes: $releaseNotes,
50+
changelog: $changelog,
51+
compareUrlTargetRevision: $compareUrlTargetRevision
52+
);
4653
} else {
4754
$changelog = $this->pasteReleaseNotesAtTheTop->execute($latestVersion, $releaseNotes, $releaseDate, $changelog);
4855
}

app/Actions/PasteReleaseNotesBelowUnreleasedHeading.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ public function __construct(
3737
/**
3838
* @throws Throwable
3939
*/
40-
public function execute(Heading $unreleasedHeading, string $latestVersion, string $releaseDate, string $releaseNotes, Document $changelog): Document
40+
public function execute(Heading $unreleasedHeading, string $latestVersion, string $releaseDate, string $releaseNotes, Document $changelog, string $compareUrlTargetRevision): Document
4141
{
4242
$previousVersion = $this->getPreviousVersionFromUnreleasedHeading($unreleasedHeading);
4343
$repositoryUrl = $this->getRepositoryUrlFromUnreleasedHeading($unreleasedHeading);
44-
$updatedUrl = $this->generateCompareUrl->generate($repositoryUrl, $latestVersion, 'HEAD');
44+
$updatedUrl = $this->generateCompareUrl->generate($repositoryUrl, $latestVersion, $compareUrlTargetRevision);
4545

4646
$link = $this->getLinkNodeFromHeading($unreleasedHeading);
4747
$link->setUrl($updatedUrl);

app/Commands/.gitkeep

Whitespace-only changes.

app/Commands/UpdateCommand.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
class UpdateCommand extends Command
1414
{
1515
protected $signature = 'update
16-
{--release-notes= : Markdown Release Notes to be added to the CHANGELOG}
17-
{--latest-version= : The version the CHANGELOG should be updated too}
16+
{--release-notes= : Markdown Release Notes to be added to the CHANGELOG.}
17+
{--latest-version= : The version the CHANGELOG should be updated too.}
1818
{--release-date= : Date when latest version has been released. Defaults to today.}
19-
{--path-to-changelog=CHANGELOG.md : Path to changelog markdown file to be updated}
19+
{--path-to-changelog=CHANGELOG.md : Path to changelog markdown file to be updated.}
20+
{--compare-url-target-revision=HEAD : Target revision used in the compare URL of possible "Unreleased" heading.}
2021
{-w\--write : Write changes to file}
2122
';
2223

@@ -33,6 +34,7 @@ public function handle(AddReleaseNotesToChangelog $addReleaseNotesToChangelog):
3334
$latestVersion = $this->option('latest-version');
3435
$releaseDate = $this->option('release-date');
3536
$pathToChangelog = $this->option('path-to-changelog');
37+
$compareUrlTargetRevision = $this->option('compare-url-target-revision');
3638

3739
if (empty($releaseDate)) {
3840
$releaseDate = now()->format('Y-m-d');
@@ -44,7 +46,8 @@ public function handle(AddReleaseNotesToChangelog $addReleaseNotesToChangelog):
4446
originalChangelog: $changelog,
4547
releaseNotes: $releaseNotes,
4648
latestVersion: $latestVersion,
47-
releaseDate: $releaseDate
49+
releaseDate: $releaseDate,
50+
compareUrlTargetRevision: $compareUrlTargetRevision
4851
);
4952

5053
$this->info($updatedChangelog->getContent());

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@
3939
"config": {
4040
"preferred-install": "dist",
4141
"sort-packages": true,
42-
"optimize-autoloader": true
42+
"optimize-autoloader": true,
43+
"allow-plugins": {
44+
"pestphp/pest-plugin": true
45+
}
4346
},
4447
"scripts": {
4548
"build": "php changelog-updater app:build",

0 commit comments

Comments
 (0)