Skip to content

Commit 26d7f9f

Browse files
awcjackfgreinacher
andauthored
fix(verify): Allow url asset not specifying path #382 (#387)
Co-authored-by: Florian Greinacher <[email protected]>
1 parent d58de9b commit 26d7f9f

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

lib/verify.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ const canBeDisabled = (validator) => (value) => value === false || validator(val
1515

1616
const VALIDATORS = {
1717
assets: isArrayOf(
18-
(asset) => isStringOrStringArray(asset) || (isPlainObject(asset) && isStringOrStringArray(asset.path))
18+
(asset) =>
19+
isStringOrStringArray(asset) ||
20+
(isPlainObject(asset) && (isNonEmptyString(asset.url) || isStringOrStringArray(asset.path)))
1921
),
2022
failTitle: canBeDisabled(isNonEmptyString),
2123
failComment: canBeDisabled(isNonEmptyString),

test/verify.test.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,3 +833,68 @@ test.serial('Does not throw an error for option without validator', async (t) =>
833833
);
834834
t.true(gitlab.isDone());
835835
});
836+
837+
test.serial(
838+
'Won\'t throw SemanticReleaseError if "assets" option is an Array of objects with url field but missing the "path" property',
839+
async (t) => {
840+
const owner = 'test_user';
841+
const repo = 'test_repo';
842+
const env = {GITLAB_TOKEN: 'gitlab_token'};
843+
const assets = [{url: 'https://gitlab.com/gitlab-org/gitlab/-/blob/master/README.md'}];
844+
const gitlab = authenticate(env)
845+
.get(`/projects/${owner}%2F${repo}`)
846+
.reply(200, {permissions: {project_access: {access_level: 40}}});
847+
848+
await t.notThrowsAsync(
849+
verify(
850+
{assets},
851+
{env, options: {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`}, logger: t.context.logger}
852+
)
853+
);
854+
t.true(gitlab.isDone());
855+
}
856+
);
857+
858+
test.serial(
859+
'Won\'t throw SemanticReleaseError if "assets" option is an Array of objects with path field but missing the "url" property',
860+
async (t) => {
861+
const owner = 'test_user';
862+
const repo = 'test_repo';
863+
const env = {GITLAB_TOKEN: 'gitlab_token'};
864+
const assets = [{path: 'README.md'}];
865+
const gitlab = authenticate(env)
866+
.get(`/projects/${owner}%2F${repo}`)
867+
.reply(200, {permissions: {project_access: {access_level: 40}}});
868+
869+
await t.notThrowsAsync(
870+
verify(
871+
{assets},
872+
{env, options: {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`}, logger: t.context.logger}
873+
)
874+
);
875+
t.true(gitlab.isDone());
876+
}
877+
);
878+
879+
test.serial(
880+
'Throw SemanticReleaseError if "assets" option is an Array of objects without url nor path property',
881+
async (t) => {
882+
const owner = 'test_user';
883+
const repo = 'test_repo';
884+
const env = {GITLAB_TOKEN: 'gitlab_token'};
885+
const assets = [{name: 'README.md'}];
886+
const gitlab = authenticate(env)
887+
.get(`/projects/${owner}%2F${repo}`)
888+
.reply(200, {permissions: {project_access: {access_level: 40}}});
889+
890+
const [error] = await t.throwsAsync(
891+
verify(
892+
{assets},
893+
{env, options: {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`}, logger: t.context.logger}
894+
)
895+
);
896+
t.is(error.name, 'SemanticReleaseError');
897+
t.is(error.code, 'EINVALIDASSETS');
898+
t.true(gitlab.isDone());
899+
}
900+
);

0 commit comments

Comments
 (0)