Repository: semantic-release/gitlab
Pull request #387 (2022-05-29 17:18:27)

fix(verify): Allow url asset not specifying path #382
Fix https://github.com/semantic-release/gitlab/issues/382

Validator accept url asset not specifying `path` property


Patch:
diff --git a/lib/verify.js b/lib/verify.js
index f31e1b2..18b2206 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),


Test patch:
diff --git a/test/verify.test.js b/test/verify.test.js
index 5a88d95..edff6cf 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());
+  }
+);