diff --git a/packages/ckeditor5-dev-env/lib/release-tools/utils/transform-commit/transform-commit-utils.js b/packages/ckeditor5-dev-env/lib/release-tools/utils/transform-commit/transform-commit-utils.js index 954e2833d..6692261a4 100644 --- a/packages/ckeditor5-dev-env/lib/release-tools/utils/transform-commit/transform-commit-utils.js +++ b/packages/ckeditor5-dev-env/lib/release-tools/utils/transform-commit/transform-commit-utils.js @@ -77,13 +77,26 @@ const transformCommitUtils = { } const packageJson = getPackageJson(); - const issuesUrl = ( typeof packageJson.bugs === 'object' ) ? packageJson.bugs.url : packageJson.bugs; + + // Due to merging our issue trackers, `packageJson.bugs` will point to the same place for every package. + // We cannot rely on this value anymore. See: https://github.com/ckeditor/ckeditor5/issues/1988. + // Instead of we can take a value from `packageJson.repository` and adjust it to match to our requirements. + let issuesUrl = ( typeof packageJson.repository === 'object' ) ? packageJson.repository.url : packageJson.repository; if ( !issuesUrl ) { - throw new Error( `The package.json for "${ packageJson.name }" must contain the "bugs" property.` ); + throw new Error( `The package.json for "${ packageJson.name }" must contain the "repository" property.` ); + } + + // If the value ends with ".git", we need to remove it. + issuesUrl = issuesUrl.replace( /\.git$/, '' ); + + // If the value contains "/issues" suffix, we don't need to add it. + if ( issuesUrl.match( /\/issues/ ) ) { + return `[#${ issueId }](${ issuesUrl }/${ issueId })`; } - return `[#${ issueId }](${ issuesUrl }/${ issueId })`; + // But if doesn't, let's add it. + return `[#${ issueId }](${ issuesUrl }/issues/${ issueId })`; } ); }, diff --git a/packages/ckeditor5-dev-env/tests/release-tools/utils/generatechangelogfromcommits-integration.js b/packages/ckeditor5-dev-env/tests/release-tools/utils/generatechangelogfromcommits-integration.js index f3c7f3640..5fd2dab1c 100644 --- a/packages/ckeditor5-dev-env/tests/release-tools/utils/generatechangelogfromcommits-integration.js +++ b/packages/ckeditor5-dev-env/tests/release-tools/utils/generatechangelogfromcommits-integration.js @@ -39,8 +39,7 @@ describe( 'dev-env/release-tools/utils', () => { const packageJson = { name: '@ckeditor/ckeditor5-test-package', - bugs: `${ url }/issues`, - repository: url + repository: `${ url }` }; fs.writeFileSync( diff --git a/packages/ckeditor5-dev-env/tests/release-tools/utils/transform-commit/transform-commit-utils.js b/packages/ckeditor5-dev-env/tests/release-tools/utils/transform-commit/transform-commit-utils.js index b02179032..4b65bb634 100644 --- a/packages/ckeditor5-dev-env/tests/release-tools/utils/transform-commit/transform-commit-utils.js +++ b/packages/ckeditor5-dev-env/tests/release-tools/utils/transform-commit/transform-commit-utils.js @@ -90,30 +90,76 @@ describe( 'dev-env/release-tools/utils/transform-commit', () => { } ); describe( 'linkToGithubIssue()', () => { - it( 'throws an error if package.json does not contain the "bugs" property', () => { + it( 'throws an error if package.json does not contain the "repository" property', () => { stubs.getPackageJson.returns( { name: 'test-package' } ); expect( () => transformCommit.linkToGithubIssue( '#123' ) ) - .to.throw( Error, 'The package.json for "test-package" must contain the "bugs" property.' ); + .to.throw( Error, 'The package.json for "test-package" must contain the "repository" property.' ); } ); - it( 'replaces "#ID" with a link to GitHub issue (packageJson.bugs as a string)', () => { + it( 'replaces "#ID" with a link to GitHub issue (packageJson.repository as a string)', () => { stubs.getPackageJson.returns( { name: 'test-package', - bugs: '/issues' + repository: 'https://github.com/ckeditor/ckeditor5-dev' } ); expect( transformCommit.linkToGithubIssue( 'Some issue #1.' ) ) - .to.equal( 'Some issue [#1](/issues/1).' ); + .to.equal( 'Some issue [#1](https://github.com/ckeditor/ckeditor5-dev/issues/1).' ); + } ); + + it( 'replaces "#ID" with a link to GitHub issue (packageJson.repository as a string, contains "/issues")', () => { + stubs.getPackageJson.returns( { + name: 'test-package', + repository: 'https://github.com/ckeditor/ckeditor5-dev/issues' + } ); + + expect( transformCommit.linkToGithubIssue( 'Some issue #1.' ) ) + .to.equal( 'Some issue [#1](https://github.com/ckeditor/ckeditor5-dev/issues/1).' ); + } ); + + it( 'replaces "#ID" with a link to GitHub issue (packageJson.repository as a string, ends with ".git")', () => { + stubs.getPackageJson.returns( { + name: 'test-package', + repository: 'https://github.com/ckeditor/ckeditor5-dev.git' + } ); + + expect( transformCommit.linkToGithubIssue( 'Some issue #1.' ) ) + .to.equal( 'Some issue [#1](https://github.com/ckeditor/ckeditor5-dev/issues/1).' ); + } ); + + it( 'replaces "#ID" with a link to GitHub issue (packageJson.repository as an object)', () => { + stubs.getPackageJson.returns( { + name: 'test-package', + repository: { + url: 'https://github.com/ckeditor/ckeditor5-dev' + } + } ); + + expect( transformCommit.linkToGithubIssue( 'Some issue #1.' ) ) + .to.equal( 'Some issue [#1](https://github.com/ckeditor/ckeditor5-dev/issues/1).' ); + } ); + + it( 'replaces "#ID" with a link to GitHub issue (packageJson.repository as an object, contains "/issues")', () => { + stubs.getPackageJson.returns( { + name: 'test-package', + repository: { + url: 'https://github.com/ckeditor/ckeditor5-dev/issues', + type: 'git' + } + } ); + + expect( transformCommit.linkToGithubIssue( 'Some issue #1.' ) ) + .to.equal( 'Some issue [#1](https://github.com/ckeditor/ckeditor5-dev/issues/1).' ); } ); - it( 'replaces "#ID" with a link to GitHub issue (packageJson.bugs as an object)', () => { + it( 'replaces "#ID" with a link to GitHub issue (packageJson.repository as an object, ends with ".git")', () => { stubs.getPackageJson.returns( { name: 'test-package', - bugs: { - url: 'https://github.com/ckeditor/ckeditor5-dev/issues' + repository: { + url: 'https://github.com/ckeditor/ckeditor5-dev.git', + type: 'git' } } ); diff --git a/packages/ckeditor5-dev-env/tests/release-tools/utils/transform-commit/transformcommitforsubrepository.js b/packages/ckeditor5-dev-env/tests/release-tools/utils/transform-commit/transformcommitforsubrepository.js index 13067dba0..ca7fe9347 100644 --- a/packages/ckeditor5-dev-env/tests/release-tools/utils/transform-commit/transformcommitforsubrepository.js +++ b/packages/ckeditor5-dev-env/tests/release-tools/utils/transform-commit/transformcommitforsubrepository.js @@ -11,7 +11,7 @@ const mockery = require( 'mockery' ); describe( 'dev-env/release-tools/utils/transform-commit', () => { describe( 'transformCommitForSubRepository()', () => { - let transformCommitForSubRepository, sandbox; + let transformCommitForSubRepository, sandbox, stubs; beforeEach( () => { sandbox = sinon.createSandbox(); @@ -22,6 +22,16 @@ describe( 'dev-env/release-tools/utils/transform-commit', () => { warnOnUnregistered: false } ); + stubs = { + getPackageJson: () => { + return { + repository: 'https://github.com/ckeditor/ckeditor5-dev' + }; + } + }; + + mockery.registerMock( '../getpackagejson', stubs.getPackageJson ); + transformCommitForSubRepository = require( '../../../../lib/release-tools/utils/transform-commit/transformcommitforsubrepository' );