From 24a8fb94f9dc976fa75f8e4d44b20906b65a6e02 Mon Sep 17 00:00:00 2001 From: Florian Greinacher Date: Thu, 14 Apr 2022 16:52:42 +0200 Subject: [PATCH] fix(verify): gracefully handle options without validator (#364) --- lib/verify.js | 9 ++++++--- test/verify.test.js | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/verify.js b/lib/verify.js index 4b523e2d..027231d7 100644 --- a/lib/verify.js +++ b/lib/verify.js @@ -32,11 +32,14 @@ module.exports = async (pluginConfig, context) => { debug('apiUrl: %o', gitlabApiUrl); debug('repoId: %o', repoId); + const isValid = (option, value) => { + const validator = VALIDATORS[option]; + return isNil(value) || isNil(validator) || VALIDATORS[option](value); + }; + const errors = Object.entries({...options}).reduce( (errors, [option, value]) => - !isNil(value) && !VALIDATORS[option](value) - ? [...errors, getError(`EINVALID${option.toUpperCase()}`, {[option]: value})] - : errors, + isValid(option, value) ? errors : [...errors, getError(`EINVALID${option.toUpperCase()}`, {[option]: value})], [] ); diff --git a/test/verify.test.js b/test/verify.test.js index 2c9f91bf..7a66e6ac 100644 --- a/test/verify.test.js +++ b/test/verify.test.js @@ -783,3 +783,22 @@ test.serial('Throw SemanticReleaseError if "assignee" option is a whitespace Str t.is(error.code, 'EINVALIDASSIGNEE'); t.true(gitlab.isDone()); }); + +test.serial('Does not throw an error for option without validator', async t => { + const owner = 'test_user'; + const repo = 'test_repo'; + const env = {GL_TOKEN: 'gitlab_token'}; + const gitlab = authenticate(env) + .get(`/projects/${owner}%2F${repo}`) + .reply(200, {permissions: {project_access: {access_level: 30}}}); + + await t.notThrowsAsync( + verify( + { + someOption: 42, + }, + {env, options: {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`}, logger: t.context.logger} + ) + ); + t.true(gitlab.isDone()); +});