Skip to content

Commit

Permalink
fix(verify): gracefully handle options without validator (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
fgreinacher committed Apr 14, 2022
1 parent bea6b3c commit 24a8fb9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/verify.js
Expand Up @@ -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})],
[]
);

Expand Down
19 changes: 19 additions & 0 deletions test/verify.test.js
Expand Up @@ -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());
});

0 comments on commit 24a8fb9

Please sign in to comment.