From e887626d162e9a3be3b25434db49c1067619e6e7 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Mon, 20 May 2019 11:55:13 -0700 Subject: [PATCH] fix: extend release notes regex to support patches (#142) --- __snapshots__/github-release.js | 14 +++++++++++++ src/github-release.ts | 4 +++- test/fixtures/CHANGELOG-bug-140.md | 32 ++++++++++++++++++++++++++++++ test/github-release.ts | 10 ++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/CHANGELOG-bug-140.md diff --git a/__snapshots__/github-release.js b/__snapshots__/github-release.js index 109f0ebd4..89812b84e 100644 --- a/__snapshots__/github-release.js +++ b/__snapshots__/github-release.js @@ -1,3 +1,17 @@ +exports['GitHubRelease extractLatestReleaseNotes extracts appropriate release notes when prior release is patch 1'] = ` + + +### ⚠ BREAKING CHANGES + +* temp directory now defaults to setting for report directory + +### Features + +* default temp directory to report directory ([#102](https://www.github.com/bcoe/c8/issues/102)) ([8602f4a](https://www.github.com/bcoe/c8/commit/8602f4a)) +* load .nycrc/.nycrc.json to simplify migration ([#100](https://www.github.com/bcoe/c8/issues/100)) ([bd7484f](https://www.github.com/bcoe/c8/commit/bd7484f)) + +` + exports['GitHubRelease extractLatestReleaseNotes handles CHANGELOG with new format entries 1'] = ` diff --git a/src/github-release.ts b/src/github-release.ts index 09e3db2cc..84323baf7 100644 --- a/src/github-release.ts +++ b/src/github-release.ts @@ -80,7 +80,9 @@ export class GitHubRelease { string { version = version.replace(/^v/, ''); const latestRe = new RegExp( - `## v?\\[?${version}[^\\n]*\\n(.*?)(\\n##\\s|($(?![\r\n])))`, 'ms'); + `## v?\\[?${ + version}[^\\n]*\\n(.*?)(\\n##\\s|\\n### \\[?[0-9]+\\.|($(?![\r\n])))`, + 'ms'); const match = changelogContents.match(latestRe); if (!match) { throw Error('could not find changelog entry corresponding to release PR'); diff --git a/test/fixtures/CHANGELOG-bug-140.md b/test/fixtures/CHANGELOG-bug-140.md new file mode 100644 index 000000000..208d7c996 --- /dev/null +++ b/test/fixtures/CHANGELOG-bug-140.md @@ -0,0 +1,32 @@ +# Changelog + +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +## [5.0.0](https://www.github.com/bcoe/c8/compare/v4.1.5...v5.0.0) (2019-05-20) + + +### ⚠ BREAKING CHANGES + +* temp directory now defaults to setting for report directory + +### Features + +* default temp directory to report directory ([#102](https://www.github.com/bcoe/c8/issues/102)) ([8602f4a](https://www.github.com/bcoe/c8/commit/8602f4a)) +* load .nycrc/.nycrc.json to simplify migration ([#100](https://www.github.com/bcoe/c8/issues/100)) ([bd7484f](https://www.github.com/bcoe/c8/commit/bd7484f)) + +### [4.1.5](https://github.com/bcoe/c8/compare/v4.1.4...v4.1.5) (2019-05-11) + + +### Bug Fixes + +* exit with code 1 when report output fails ([#92](https://github.com/bcoe/c8/issues/92)) ([a27b694](https://github.com/bcoe/c8/commit/a27b694)) +* remove the unmaintained mkdirp dependency ([#91](https://github.com/bcoe/c8/issues/91)) ([a465b65](https://github.com/bcoe/c8/commit/a465b65)) + + + +## [4.1.4](https://github.com/bcoe/c8/compare/v4.1.3...v4.1.4) (2019-05-03) + + +### Bug Fixes + +* we were not exiting with 1 if mkdir failed ([#89](https://github.com/bcoe/c8/issues/89)) ([fb02ed6](https://github.com/bcoe/c8/commit/fb02ed6)) diff --git a/test/github-release.ts b/test/github-release.ts index 91c7f08a9..d8b3836f3 100644 --- a/test/github-release.ts +++ b/test/github-release.ts @@ -50,5 +50,15 @@ describe('GitHubRelease', () => { GitHubRelease.extractLatestReleaseNotes(changelogContent, 'v1.2.0'); snapshot(latestReleaseNotes); }); + + // see: https://github.com/googleapis/release-please/issues/140 + it('extracts appropriate release notes when prior release is patch', () => { + const changelogContent = + readFileSync(resolve(fixturesPath, './CHANGELOG-bug-140.md'), 'utf8') + .replace(/\r\n/g, '\n'); + const latestReleaseNotes = + GitHubRelease.extractLatestReleaseNotes(changelogContent, 'v5.0.0'); + snapshot(latestReleaseNotes); + }); }); });