Skip to content
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

fix(verify): gracefully handle options without validator #364

Merged
merged 1 commit into from Apr 14, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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());
});