Skip to content

Commit 24a8fb9

Browse files
authored
fix(verify): gracefully handle options without validator (#364)
1 parent bea6b3c commit 24a8fb9

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

lib/verify.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@ module.exports = async (pluginConfig, context) => {
3232
debug('apiUrl: %o', gitlabApiUrl);
3333
debug('repoId: %o', repoId);
3434

35+
const isValid = (option, value) => {
36+
const validator = VALIDATORS[option];
37+
return isNil(value) || isNil(validator) || VALIDATORS[option](value);
38+
};
39+
3540
const errors = Object.entries({...options}).reduce(
3641
(errors, [option, value]) =>
37-
!isNil(value) && !VALIDATORS[option](value)
38-
? [...errors, getError(`EINVALID${option.toUpperCase()}`, {[option]: value})]
39-
: errors,
42+
isValid(option, value) ? errors : [...errors, getError(`EINVALID${option.toUpperCase()}`, {[option]: value})],
4043
[]
4144
);
4245

test/verify.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,3 +783,22 @@ test.serial('Throw SemanticReleaseError if "assignee" option is a whitespace Str
783783
t.is(error.code, 'EINVALIDASSIGNEE');
784784
t.true(gitlab.isDone());
785785
});
786+
787+
test.serial('Does not throw an error for option without validator', async t => {
788+
const owner = 'test_user';
789+
const repo = 'test_repo';
790+
const env = {GL_TOKEN: 'gitlab_token'};
791+
const gitlab = authenticate(env)
792+
.get(`/projects/${owner}%2F${repo}`)
793+
.reply(200, {permissions: {project_access: {access_level: 30}}});
794+
795+
await t.notThrowsAsync(
796+
verify(
797+
{
798+
someOption: 42,
799+
},
800+
{env, options: {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`}, logger: t.context.logger}
801+
)
802+
);
803+
t.true(gitlab.isDone());
804+
});

0 commit comments

Comments
 (0)