Skip to content

Commit

Permalink
Merge pull request #757 from ckeditor/ck/11322
Browse files Browse the repository at this point in the history
Fix (env): Fixed `changelog.getChangesForVersion()` util leaking to other releases. Closes ckeditor/ckeditor5#11322.
  • Loading branch information
pomek authored Mar 4, 2022
2 parents 34f35fb + bd14ed4 commit bca6938
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const utils = {
version = version.replace( /^v/, '' );

const changelog = utils.getChangelog( cwd ).replace( utils.changelogHeader, '\n' );
const match = changelog.match( new RegExp( `\\n(## \\[?${ version }\\]?[\\s\\S]+?)(?:\\n## \\[|$)` ) );
const match = changelog.match( new RegExp( `\\n(## \\[?${ version }\\]?[\\s\\S]+?)(?:\\n## \\[?|$)` ) );

if ( !match || !match[ 1 ] ) {
return null;
Expand Down
206 changes: 154 additions & 52 deletions packages/ckeditor5-dev-env/tests/release-tools/utils/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ describe( 'dev-env/release-tools/utils', () => {
'* Cloned the main module. ([abcd123](https://github.com))'
].join( '\n' );

const changelog =
`## [0.1.0](https://github.com) (2017-01-13)
${ expectedChangelog }`;
const changelog = [
'## [0.1.0](https://github.com) (2017-01-13)',
'',
expectedChangelog
].join( '\n' );

const currentChangelogStub = sandbox.stub( utils, 'getChangelog' )
.returns( utils.changelogHeader + changelog );
Expand All @@ -58,10 +59,11 @@ ${ expectedChangelog }`;
'* Cloned the main module. ([abcd123](https://github.com))'
].join( '\n' );

const changelog =
`## 0.1.0 (2017-01-13)
${ expectedChangelog }`;
const changelog = [
'## 0.1.0 (2017-01-13)',
'',
expectedChangelog
].join( '\n' );

const currentChangelogStub = sandbox.stub( utils, 'getChangelog' )
.returns( utils.changelogHeader + changelog );
Expand All @@ -73,25 +75,27 @@ ${ expectedChangelog }`;
} );

it( 'returns changes between tags', () => {
const expectedChangelog =
`### Features
* Cloned the main module. ([abcd123](https://github.com))
### BREAKING CHANGE
* Bump the major!`;

const changelog =
`## [1.0.0](https://github.com/) (2017-01-13)
${ expectedChangelog }
## [0.1.0](https://github.com) (2017-01-13)
### Features
const expectedChangelog = [
'### Features',
'',
'* Cloned the main module. ([abcd123](https://github.com))',
'',
'### BREAKING CHANGE',
'',
'* Bump the major!'
].join( '\n' );

* Cloned the main module. ([abcd123](https://github.com))`;
const changelog = [
'## [1.0.0](https://github.com/) (2017-01-13)',
'',
expectedChangelog,
'',
'## [0.1.0](https://github.com) (2017-01-13)',
'',
'### Features',
'',
'* Cloned the main module. ([abcd123](https://github.com))'
].join( '\n' );

const currentChangelogStub = sandbox.stub( utils, 'getChangelog' )
.returns( utils.changelogHeader + changelog );
Expand All @@ -103,34 +107,50 @@ ${ expectedChangelog }
} );

it( 'returns null if cannot find changes for the specified version', () => {
const changelog =
`## [0.1.0](https://github.com) (2017-01-13)
### Features
* Cloned the main module. ([abcd123](https://github.com))`;
const changelog = [
'## [0.1.0](https://github.com) (2017-01-13)',
'',
'### Features',
'',
'* Cloned the main module. ([abcd123](https://github.com))'
].join( '\n' );

sandbox.stub( utils, 'getChangelog' )
.returns( utils.changelogHeader + changelog );

expect( utils.getChangesForVersion( 'v1.0.0' ) ).to.equal( null );
} );

it( 'does not leak or stop too early', () => {
const changelog =
`## [0.3.0](https://github.com) (2017-01-13)
3
Some text ## [like a release header]
## [0.2.0](https://github.com) (2017-01-13)
it( 'works when date is not specified', () => {
const changelog = [
'## 0.3.0',
'',
'Foo'
].join( '\n' );

2
sandbox.stub( utils, 'getChangelog' )
.returns( utils.changelogHeader + changelog );

## [0.1.0](https://github.com) (2017-01-13)
expect( utils.getChangesForVersion( 'v0.3.0' ) )
.to.equal( 'Foo' );
} );

1`;
it( 'captures correct range of changes (headers are URLs)', () => {
const changelog = [
'## [0.3.0](https://github.com) (2017-01-13)',
'',
'3',
'',
'Some text ## [like a release header]',
'',
'## [0.2.0](https://github.com) (2017-01-13)',
'',
'2',
'',
'## [0.1.0](https://github.com) (2017-01-13)',
'',
'1'
].join( '\n' );

sandbox.stub( utils, 'getChangelog' )
.returns( utils.changelogHeader + changelog );
Expand All @@ -142,17 +162,99 @@ Some text ## [like a release header]
.to.equal( '2' );
} );

it( 'works when date is not specified', () => {
const changelog =
`## 0.3.0
it( 'captures correct range of changes (headers are plain text, "the initial" release check)', () => {
const changelog = [
'Changelog',
'=========',
'',
'## 1.0.2 (2022-02-22)',
'',
'### Other changes',
'',
'* Other change for `1.0.2`.',
'',
'',
'## 1.0.1 (2022-02-22)',
'',
'### Other changes',
'',
'* Other change for `1.0.1`.',
'',
'',
'## 1.0.0 (2022-02-22)',
'',
'This is the initial release.'
].join( '\n' );

Foo`;
sandbox.stub( utils, 'getChangelog' ).returns( utils.changelogHeader + changelog );

sandbox.stub( utils, 'getChangelog' )
.returns( utils.changelogHeader + changelog );
expect( utils.getChangesForVersion( '1.0.0' ) ).to.equal( 'This is the initial release.' );
} );

expect( utils.getChangesForVersion( 'v0.3.0' ) )
.to.equal( 'Foo' );
it( 'captures correct range of changes (headers are plain text, "middle" version check)', () => {
const changelog = [
'Changelog',
'=========',
'',
'## 1.0.2 (2022-02-22)',
'',
'### Other changes',
'',
'* Other change for `1.0.2`.',
'',
'',
'## 1.0.1 (2022-02-22)',
'',
'### Other changes',
'',
'* Other change for `1.0.1`.',
'',
'',
'## 1.0.0 (2022-02-22)',
'',
'This is the initial release.'
].join( '\n' );

sandbox.stub( utils, 'getChangelog' ).returns( utils.changelogHeader + changelog );

expect( utils.getChangesForVersion( '1.0.1' ) ).to.equal( [
'### Other changes',
'',
'* Other change for `1.0.1`.'
].join( '\n' ) );
} );

it( 'captures correct range of changes (headers are plain text, "the latest" check)', () => {
const changelog = [
'Changelog',
'=========',
'',
'## 1.0.2 (2022-02-22)',
'',
'### Other changes',
'',
'* Other change for `1.0.2`.',
'',
'',
'## 1.0.1 (2022-02-22)',
'',
'### Other changes',
'',
'* Other change for `1.0.1`.',
'',
'',
'## 1.0.0 (2022-02-22)',
'',
'This is the initial release.'
].join( '\n' );

sandbox.stub( utils, 'getChangelog' ).returns( utils.changelogHeader + changelog );

expect( utils.getChangesForVersion( '1.0.2' ) ).to.equal( [
'### Other changes',
'',
'* Other change for `1.0.2`.'
].join( '\n' ) );
} );
} );

Expand Down

0 comments on commit bca6938

Please sign in to comment.