diff --git a/lib/verify.js b/lib/verify.js index f31e1b2d..18b22066 100644 --- a/lib/verify.js +++ b/lib/verify.js @@ -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), diff --git a/test/verify.test.js b/test/verify.test.js index 5a88d95f..edff6cf0 100644 --- a/test/verify.test.js +++ b/test/verify.test.js @@ -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()); + } +);