Skip to content

Commit

Permalink
Merge pull request #552 from ckeditor/t/ckeditor5/1988
Browse files Browse the repository at this point in the history
Other: Adjusted the changelog generator to match to planned changes related to merging issue trackers. Closes ckeditor/ckeditor5#1988.

BREAKING CHANGE: Due to merging our issue trackers, pkgJson.bugs will point to the same place for every package. We cannot rely on this value anymore. See ckeditor/ckeditor5#1988. Instead of we can take a value from pkgJson.repository and adjust it to match to our requirements.
  • Loading branch information
Reinmar committed Aug 26, 2019
2 parents ebdec66 + c05e7a1 commit acfe1a6
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 })`;
} );
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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'
);
Expand Down

0 comments on commit acfe1a6

Please sign in to comment.