Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion packages/shipjs-lib/src/lib/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export const GIT_COMMIT_PREFIX_PATCH = new Set([

export const GIT_COMMIT_PREFIX_MINOR = new Set(['feat']);

export const GIT_COMMIT_BREAKING_CHANGE = 'BREAKING CHANGE';
export const GIT_COMMIT_BREAKING_CHANGE = /^BREAKING[ -]CHANGE\s*:/;

export const RELEASE_BRANCH = 'releases';
49 changes: 49 additions & 0 deletions packages/shipjs-lib/src/lib/util/__tests__/getNextVersion.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,55 @@ describe('getNextVersionFromCommitMessages', () => {
expect(actual).toBe('1.0.0');
});

it('detects major from BREAKING-CHANGE with hyphen', () => {
const version = '1.2.3';
const titles = 'feat: abc';
const bodies = 'BREAKING-CHANGE: this also breaks things.';
const { version: actual } = getNextVersionFromCommitMessages(
version,
titles,
bodies
);
expect(actual).toBe('2.0.0');
});

it('does not trigger major from prose mentioning breaking changes', () => {
const version = '1.2.3';
const titles = 'feat: upgrade storybook';
const bodies =
'This PR includes breaking changes around package consolidation.';
const { version: actual } = getNextVersionFromCommitMessages(
version,
titles,
bodies
);
expect(actual).toBe('1.3.0');
});

it('detects major from ! suffix in title', () => {
const version = '1.2.3';
const titles = 'feat!: remove deprecated API';
const bodies = '';
const { version: actual } = getNextVersionFromCommitMessages(
version,
titles,
bodies
);
expect(actual).toBe('2.0.0');
});

it('detects major from scoped ! suffix in title', () => {
const version = '1.2.3';
const titles = 'fix(auth)!: change token format';
const bodies = '';
const { version: actual } = getNextVersionFromCommitMessages(
version,
titles,
bodies
);
expect(actual).toBe('2.0.0');
});

it('gets a null with no commit messages', () => {
const version = '0.0.1';
const titles = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function getCommitNumbersPerType(commitTitles) {
ignoredMessages.push(title);
return;
}
const prefix = match[1].toLowerCase();
const prefix = match[1].replace(/!$/, '').toLowerCase();
if (
GIT_COMMIT_PREFIX_PATCH.has(prefix) ||
GIT_COMMIT_PREFIX_MINOR.has(prefix)
Expand Down
5 changes: 4 additions & 1 deletion packages/shipjs-lib/src/lib/util/getNextVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ export function getNextVersionFromCommitMessages(version, titles, bodies) {
bodies
.toUpperCase()
.split('\n')
.some((line) => line.startsWith(GIT_COMMIT_BREAKING_CHANGE))
.some((line) => GIT_COMMIT_BREAKING_CHANGE.test(line.trim()))
) {
return { version: inc(version, 'major') };
}
if (titles.split('\n').some((line) => /^\w+(\(.*?\))?!:/.test(line.trim()))) {
return { version: inc(version, 'major') };
}
const { numbers, ignoredMessages } = getCommitNumbersPerType(titles);
const minor = Array.from(GIT_COMMIT_PREFIX_MINOR).some(
(prefix) => numbers[prefix] > 0
Expand Down
Loading