Skip to content

feat(core): ignore version commits with footers #79

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

Merged
merged 2 commits into from
Oct 5, 2017
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
8 changes: 7 additions & 1 deletion @commitlint/core/src/library/is-ignored.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ const WILDCARDS = [
),
c => c.match(/^(R|r)evert (.*)/),
c => c.match(/^(fixup|squash)!/),
c => semver.valid(c.trim())
c =>
semver.valid(
c
.split('\n')
.shift()
.trim()
)
];

export default function isIgnored(commit = '') {
Expand Down
53 changes: 37 additions & 16 deletions @commitlint/core/src/library/is-ignored.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
import test from 'ava';
import isIgnored from './is-ignored';

const VERSION_MESSAGES = [
'0.0.1',
'0.1.0',
'1.0.0',
'0.0.1-alpha',
'0.0.1-some-crazy-tag',
'0.0.1-0',
'0.0.1-999',
'0.0.1-alpha.0',
'0.0.1-alpha.999',
'0.0.1-some-crazy-tag.0',
'0.0.1-some-crazy-tag.999',
'0.0.1-1e69d54',
'v0.0.1',
' v3.0.0'
];

const AMENDMENTS = [
'Signed-off-by: Developer <[email protected]>',
'Change-Id: I895114872a515a269487a683124b63303818e19c',
'Signed-off-by: Developer <[email protected]>\nChange-Id: I895114872a515a269487a683124b63303818e19c'
];

const AMENDED_VERSION_MESSAGES = VERSION_MESSAGES.reduce((results, message) => {
return [
...results,
...AMENDMENTS.map(amendment => `${message}\n\n${amendment}`)
];
}, []);

test('should return false when called without arguments', t => {
t.false(isIgnored());
});
Expand All @@ -13,7 +43,7 @@ test('should return false for normal commit', t => {
t.false(isIgnored('initial commit'));
});

test('should return false for branch merges', t => {
test('should return true for branch merges', t => {
t.true(isIgnored("Merge branch 'iss53'"));
});

Expand All @@ -34,21 +64,12 @@ test('should return true for revert commits', t => {
);
});

test('should return true for npm version commits', t => {
t.true(isIgnored(`0.0.1`));
t.true(isIgnored(`0.1.0`));
t.true(isIgnored(`1.0.0`));
t.true(isIgnored(`0.0.1-alpha`));
t.true(isIgnored(`0.0.1-some-crazy-tag`));
t.true(isIgnored(`0.0.1-0`));
t.true(isIgnored(`0.0.1-999`));
t.true(isIgnored(`0.0.1-alpha.0`));
t.true(isIgnored(`0.0.1-alpha.999`));
t.true(isIgnored(`0.0.1-some-crazy-tag.0`));
t.true(isIgnored(`0.0.1-some-crazy-tag.999`));
t.true(isIgnored(`0.0.1-1e69d54`));
t.true(isIgnored(`v0.0.1`));
t.true(isIgnored(` v3.0.0`));
test('should ignore npm semver commits', t => {
VERSION_MESSAGES.forEach(message => t.true(isIgnored(message)));
});

test('should ignore npm semver commits with footers', t => {
AMENDED_VERSION_MESSAGES.forEach(message => t.true(isIgnored(message)));
});

test('should return true fixup commits', t => {
Expand Down