Skip to content

Commit 0495801

Browse files
pvdlggr2m
authored andcommitted
fix: Throw error if a release rule is invalid
1 parent dc6ea59 commit 0495801

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

lib/analyze-commit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = (releaseRules, commit) => {
2424
)
2525
)
2626
.every(match => {
27-
if (match && compareReleaseTypes(releaseType, match.release)) {
27+
if (compareReleaseTypes(releaseType, match.release)) {
2828
releaseType = match.release;
2929
if (releaseType === RELEASE_TYPES[0]) {
3030
return false;

lib/load/release-rules.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ module.exports = ({releaseRules}) => {
2424
}
2525

2626
loadedReleaseRules.forEach(rule => {
27-
if (RELEASE_TYPES.indexOf(rule.release) === -1) {
27+
if (!rule || !rule.release) {
28+
throw new Error('Error in commit-analyzer configuration: rules must be an object with a "release" property');
29+
} else if (RELEASE_TYPES.indexOf(rule.release) === -1) {
2830
throw new Error(
2931
`Error in commit-analyzer configuration: "${rule.release}" is not a valid release type. Valid values are: ${JSON.stringify(
3032
RELEASE_TYPES

test/load-release-rules.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ test('Throw error if "releaseRules" reference invalid commit type', t => {
2525
() => loadReleaseRules({releaseRules: [{tag: 'Update', release: 'invalid'}]}),
2626
/Error in commit-analyzer configuration: "invalid" is not a valid release type\. Valid values are:\[?.*\]/
2727
);
28+
});
2829

30+
test('Throw error if a rule in "releaseRules" does not have a release type', t => {
31+
t.throws(
32+
() => loadReleaseRules({releaseRules: [{tag: 'Update'}]}),
33+
/Error in commit-analyzer configuration: rules must be an object with a "release" property/
34+
);
2935
});
3036

3137
test('Throw error if "releaseRules" is not an Array or a String', t => {
@@ -40,5 +46,11 @@ test('Throw error if "releaseRules" option reference a requierable module that i
4046
() => loadReleaseRules({releaseRules: './test/fixtures/release-rules-invalid'}),
4147
/Error in commit-analyzer configuration: "releaseRules" must be an array of rules/
4248
);
49+
});
4350

51+
test('Throw error if "releaseRules" contains an undefined rule', t => {
52+
t.throws(
53+
() => loadReleaseRules({releaseRules: [{type: 'feat', release: 'minor'}, undefined]}, {}),
54+
/Error in commit-analyzer configuration: rules must be an object with a "release" property/
55+
);
4456
});

0 commit comments

Comments
 (0)