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

Adjusted the changelog generator to match to planned changes related to merging issue trackers #552

Merged
merged 2 commits into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 relay on this value anymore. See: https://github.com/ckeditor/ckeditor5/issues/1988.
pomek marked this conversation as resolved.
Show resolved Hide resolved
// 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