Skip to content
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

2.7.0 #139

Closed
wants to merge 2 commits into from
Closed

2.7.0 #139

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.7.0]
### Uncategorized
- backport: Allow prerelease versions in release headers ([#130](https://github.com/MetaMask/auto-changelog/pull/130))

## [2.6.1]
### Fixed
- When fetching remote tags, order by date to account for miniscule time differences between tags created within automated tests ([#113](https://github.com/MetaMask/auto-changelog/pull/113))
Expand Down Expand Up @@ -82,7 +86,8 @@ Includes the following features:
- Monorepo support ([#41](https://github.com/MetaMask/auto-changelog/pull/41))
- Configurable repository URL, version, and changelog file path ([#33](https://github.com/MetaMask/auto-changelog/pull/33), [#31](https://github.com/MetaMask/auto-changelog/pull/31), [#30](https://github.com/MetaMask/auto-changelog/pull/30))

[Unreleased]: https://github.com/MetaMask/auto-changelog/compare/v2.6.1...HEAD
[Unreleased]: https://github.com/MetaMask/auto-changelog/compare/v2.7.0...HEAD
[2.7.0]: https://github.com/MetaMask/auto-changelog/compare/v2.6.1...v2.7.0
[2.6.1]: https://github.com/MetaMask/auto-changelog/compare/v2.6.0...v2.6.1
[2.6.0]: https://github.com/MetaMask/auto-changelog/compare/v2.5.0...v2.6.0
[2.5.0]: https://github.com/MetaMask/auto-changelog/compare/v2.4.0...v2.5.0
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/auto-changelog",
"version": "2.6.1",
"version": "2.7.0",
"description": "Utilities for validating and updating \"Keep a Changelog\" formatted changelogs",
"publishConfig": {
"registry": "https://registry.npmjs.org/",
Expand Down
65 changes: 65 additions & 0 deletions src/parse-changelog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,45 @@ describe('parseChangelog', () => {
expect(changelog.getUnreleasedChanges()).toStrictEqual({});
});

it('should parse changelog with prereleases', () => {
const changelog = parseChangelog({
changelogContent: outdent`
# Changelog
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).

## [Unreleased]

## [1.0.0-rc.1] - 2020-01-01
### Changed
- Something else

## [0.0.2-beta.1] - 2020-01-01
### Fixed
- Something

## [0.0.1-alpha.1] - 2020-01-01
### Changed
- Something

[Unreleased]: https://github.com/ExampleUsernameOrOrganization/ExampleRepository/compare/v1.0.0-rc.1...HEAD
[1.0.0-rc.1]: https://github.com/ExampleUsernameOrOrganization/ExampleRepository/compare/v0.0.2-beta.1...v1.0.0-rc.1
[0.0.2-beta.1]: https://github.com/ExampleUsernameOrOrganization/ExampleRepository/compare/v0.0.1-alpha.1...v0.0.2-beta.1
[0.0.1-alpha.1]: https://github.com/ExampleUsernameOrOrganization/ExampleRepository/releases/tag/v0.0.1-alpha.1
`,
repoUrl:
'https://github.com/ExampleUsernameOrOrganization/ExampleRepository',
});

expect(changelog.getReleases()).toStrictEqual([
{ date: '2020-01-01', status: undefined, version: '1.0.0-rc.1' },
{ date: '2020-01-01', status: undefined, version: '0.0.2-beta.1' },
{ date: '2020-01-01', status: undefined, version: '0.0.1-alpha.1' },
]);
});

it('should parse changelog with release statuses', () => {
const changelog = parseChangelog({
changelogContent: outdent`
Expand Down Expand Up @@ -499,6 +538,32 @@ describe('parseChangelog', () => {
).toThrow(`Malformed release header: '## [1.0.0 - 2020-01-01'`);
});

it('should throw if version in release header is not SemVer-compatible', () => {
const brokenChangelog = outdent`
# Changelog
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).

## [Unreleased]

## [1.2.3.4]
### Changed
- Something else

[Unreleased]: https://github.com/ExampleUsernameOrOrganization/ExampleRepository/compare/v1.2.3.4...HEAD
[1.2.3.4]: https://github.com/ExampleUsernameOrOrganization/ExampleRepository/releases/tag/v1.2.3.4
`;
expect(() =>
parseChangelog({
changelogContent: brokenChangelog,
repoUrl:
'https://github.com/ExampleUsernameOrOrganization/ExampleRepository',
}),
).toThrow(`Invalid SemVer version in release header: '## [1.2.3.4]`);
});

it('should throw if release header uses the wrong header level', () => {
const brokenChangelog = outdent`
# Changelog
Expand Down
10 changes: 9 additions & 1 deletion src/parse-changelog.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import semver from 'semver';
import Changelog from './changelog';
import { ChangeCategory, unreleased } from './constants';

Expand Down Expand Up @@ -88,11 +89,18 @@ export function parseChangelog({
for (const line of contentfulChangelogLines) {
if (line.startsWith('## [')) {
const results = line.match(
/^## \[(\d+\.\d+\.\d+)\](?: - (\d\d\d\d-\d\d-\d\d))?(?: \[(\w+)\])?/u,
/^## \[([^[\]]+)\](?: - (\d\d\d\d-\d\d-\d\d))?(?: \[(\w+)\])?/u,
);
if (results === null) {
throw new Error(`Malformed release header: '${truncated(line)}'`);
}

if (semver.valid(results[1]) === null) {
throw new Error(
`Invalid SemVer version in release header: '${truncated(line)}'`,
);
}

// Trailing newline removed because the release section is expected to
// be prefixed by a newline.
finalizePreviousChange({
Expand Down