Skip to content

Commit

Permalink
fix(verify): Allow url asset not specifying path #382 (#387)
Browse files Browse the repository at this point in the history
Co-authored-by: Florian Greinacher <[email protected]>
  • Loading branch information
awcjack and fgreinacher committed May 31, 2022
1 parent d58de9b commit 26d7f9f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const canBeDisabled = (validator) => (value) => value === false || validator(val

const VALIDATORS = {
assets: isArrayOf(
(asset) => isStringOrStringArray(asset) || (isPlainObject(asset) && isStringOrStringArray(asset.path))
(asset) =>
isStringOrStringArray(asset) ||
(isPlainObject(asset) && (isNonEmptyString(asset.url) || isStringOrStringArray(asset.path)))
),
failTitle: canBeDisabled(isNonEmptyString),
failComment: canBeDisabled(isNonEmptyString),
Expand Down
65 changes: 65 additions & 0 deletions test/verify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -833,3 +833,68 @@ test.serial('Does not throw an error for option without validator', async (t) =>
);
t.true(gitlab.isDone());
});

test.serial(
'Won\'t throw SemanticReleaseError if "assets" option is an Array of objects with url field but missing the "path" property',
async (t) => {
const owner = 'test_user';
const repo = 'test_repo';
const env = {GITLAB_TOKEN: 'gitlab_token'};
const assets = [{url: 'https://gitlab.com/gitlab-org/gitlab/-/blob/master/README.md'}];
const gitlab = authenticate(env)
.get(`/projects/${owner}%2F${repo}`)
.reply(200, {permissions: {project_access: {access_level: 40}}});

await t.notThrowsAsync(
verify(
{assets},
{env, options: {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`}, logger: t.context.logger}
)
);
t.true(gitlab.isDone());
}
);

test.serial(
'Won\'t throw SemanticReleaseError if "assets" option is an Array of objects with path field but missing the "url" property',
async (t) => {
const owner = 'test_user';
const repo = 'test_repo';
const env = {GITLAB_TOKEN: 'gitlab_token'};
const assets = [{path: 'README.md'}];
const gitlab = authenticate(env)
.get(`/projects/${owner}%2F${repo}`)
.reply(200, {permissions: {project_access: {access_level: 40}}});

await t.notThrowsAsync(
verify(
{assets},
{env, options: {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`}, logger: t.context.logger}
)
);
t.true(gitlab.isDone());
}
);

test.serial(
'Throw SemanticReleaseError if "assets" option is an Array of objects without url nor path property',
async (t) => {
const owner = 'test_user';
const repo = 'test_repo';
const env = {GITLAB_TOKEN: 'gitlab_token'};
const assets = [{name: 'README.md'}];
const gitlab = authenticate(env)
.get(`/projects/${owner}%2F${repo}`)
.reply(200, {permissions: {project_access: {access_level: 40}}});

const [error] = await t.throwsAsync(
verify(
{assets},
{env, options: {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`}, logger: t.context.logger}
)
);
t.is(error.name, 'SemanticReleaseError');
t.is(error.code, 'EINVALIDASSETS');
t.true(gitlab.isDone());
}
);

0 comments on commit 26d7f9f

Please sign in to comment.