Skip to content

feat: support a verbose heading for the changelog #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.9.0 - TBD

### Added

- [#80](https://github.com/phly/keep-a-changelog/pull/80) adds support for more verbose changelog headings. The heading no longer must be exactly `# Changelog`. Rather, it can be `# My Project's Changelog` or `# The changelog for all the things`. The word "changelog" must still be somewhere in the heading.

### Changed

- Nothing.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- Nothing.

## 2.8.1 - 2020-09-01

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/Bump/ChangelogBump.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function updateChangelog(string $version)
$changelog = sprintf(self::TEMPLATE, $version);
$contents = file_get_contents($this->changelogFile);
$contents = preg_replace(
"/^(\# Changelog\n\n.*?)(\n\n\#\# )/s",
"/^(\# [^\n]*Changelog[^\n]*\n\n.*?)(\n\n\#\# )/si",
'$1' . $changelog . '## ',
$contents
);
Expand Down
120 changes: 120 additions & 0 deletions test/Bump/ChangelogBumpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,124 @@ public function testFindLatestVersionThrowsExceptionIfNoChangelogEntriesFound():

$bumper->findLatestVersion();
}

public function testUpdateChangelogPrependsNewEntryWhenChangelogHasExpandedHeading(): void
{
$expected = <<<'EOC'
# my/project's ChAnGeLoG of Notable Changes

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.0.0 - TBD

### Added

- Nothing.

### Changed

- Nothing.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- Nothing.

## 0.2.0 - TBD

### Added

- Nothing.

### Changed

- Nothing.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- Nothing.

## 0.1.1 - TBD

### Added

- Nothing.

### Changed

- Nothing.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- Nothing.

## 0.1.0 - 2020-08-31

### Added

- Nothing.

### Changed

- Nothing.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- Nothing.

EOC;

$tempFile = tempnam(sys_get_temp_dir(), 'KAC');
file_put_contents(
$tempFile,
file_get_contents(__DIR__ . '/../_files/CHANGELOG-WITH-EXPANDED-HEADING.md')
);
$bumper = new ChangelogBump($tempFile);

$currentVersion = $bumper->findLatestVersion();
$currentVersion = $bumper->bumpPatchVersion($currentVersion);
$bumper->updateChangelog($currentVersion);

$currentVersion = $bumper->bumpMinorVersion($currentVersion);
$bumper->updateChangelog($currentVersion);

$currentVersion = $bumper->bumpMajorVersion($currentVersion);
$bumper->updateChangelog($currentVersion);

$this->assertEquals($expected, file_get_contents($tempFile));
}
}
28 changes: 28 additions & 0 deletions test/_files/CHANGELOG-WITH-EXPANDED-HEADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# my/project's ChAnGeLoG of Notable Changes

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.1.0 - 2020-08-31

### Added

- Nothing.

### Changed

- Nothing.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- Nothing.