Skip to content

Commit a6112c4

Browse files
authored
Merge pull request #755 from aldenbe/upload-404-fix
Upload 404 fix
2 parents 775d355 + 8c7fd63 commit a6112c4

File tree

2 files changed

+45
-19
lines changed

2 files changed

+45
-19
lines changed

lib/publish.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ export default async (pluginConfig, context) => {
149149
throw error;
150150
}
151151

152-
const { url, alt } = response;
152+
const { alt, full_path } = response;
153+
const url = urlJoin(gitlabUrl, full_path);
153154

154155
assetsList.push({ label, alt, url, type, filepath });
155156

test/publish.test.js

+43-18
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ test.serial("Publish a release with templated path", async (t) => {
5656
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
5757
const generic = { path: "${env.FIXTURE}.txt", filepath: "/upload.txt" };
5858
const assets = [generic];
59-
const uploaded = { url: "/uploads/upload.txt", alt: "upload.txt" };
59+
const uploaded = {
60+
url: "/uploads/upload.txt",
61+
alt: "upload.txt",
62+
full_path: "/-/project/4/66dbcd21ec5d24ed6ea225176098d52b/upload.txt",
63+
};
6064
const gitlab = authenticate(env)
6165
.post(`/projects/${encodedRepoId}/releases`, {
6266
tag_name: nextRelease.gitTag,
@@ -65,7 +69,7 @@ test.serial("Publish a release with templated path", async (t) => {
6569
links: [
6670
{
6771
name: "upload.txt",
68-
url: `https://gitlab.com/${owner}/${repo}${uploaded.url}`,
72+
url: `https://gitlab.com${uploaded.full_path}`,
6973
filepath: "/upload.txt",
7074
},
7175
],
@@ -79,7 +83,7 @@ test.serial("Publish a release with templated path", async (t) => {
7983
const result = await publish({ assets }, { env, cwd, options, nextRelease, logger: t.context.logger });
8084

8185
t.is(result.url, `https://gitlab.com/${owner}/${repo}/-/releases/${encodedGitTag}`);
82-
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", uploaded.url]);
86+
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", `https://gitlab.com${uploaded.full_path}`]);
8387
t.deepEqual(t.context.log.args[1], ["Published GitLab release: %s", nextRelease.gitTag]);
8488
t.true(gitlab.isDone());
8589
});
@@ -93,7 +97,11 @@ test.serial("Publish a release with assets", async (t) => {
9397
const options = { repositoryUrl: `https://gitlab.com/${owner}/${repo}.git` };
9498
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
9599
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
96-
const uploaded = { url: "/uploads/file.css", alt: "file.css" };
100+
const uploaded = {
101+
url: "/uploads/file.css",
102+
alt: "file.css",
103+
full_path: "/-/project/4/66dbcd21ec5d24ed6ea225176098d52b/file.css",
104+
};
97105
const assets = [["**", "!**/*.txt", "!.dotfile"]];
98106
const gitlab = authenticate(env)
99107
.post(`/projects/${encodedRepoId}/releases`, {
@@ -103,7 +111,7 @@ test.serial("Publish a release with assets", async (t) => {
103111
links: [
104112
{
105113
name: uploaded.alt,
106-
url: `https://gitlab.com/${owner}/${repo}${uploaded.url}`,
114+
url: `https://gitlab.com${uploaded.full_path}`,
107115
},
108116
],
109117
},
@@ -116,7 +124,7 @@ test.serial("Publish a release with assets", async (t) => {
116124
const result = await publish({ assets }, { env, cwd, options, nextRelease, logger: t.context.logger });
117125

118126
t.is(result.url, `https://gitlab.com/${owner}/${repo}/-/releases/${encodedGitTag}`);
119-
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", uploaded.url]);
127+
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", `https://gitlab.com${uploaded.full_path}`]);
120128
t.deepEqual(t.context.log.args[1], ["Published GitLab release: %s", nextRelease.gitTag]);
121129
t.true(gitlabUpload.isDone());
122130
t.true(gitlab.isDone());
@@ -315,7 +323,13 @@ test.serial("Publish a release with asset type and permalink", async (t) => {
315323
const options = { repositoryUrl: `https://gitlab.com/${owner}/${repo}.git` };
316324
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
317325
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
318-
const uploaded = { url: "/uploads/file.css", alt: "file.css", link_type: "package", filepath: "/dist/file.css" };
326+
const uploaded = {
327+
url: "/uploads/file.css",
328+
alt: "file.css",
329+
link_type: "package",
330+
filepath: "/dist/file.css",
331+
full_path: "/-/project/4/66dbcd21ec5d24ed6ea225176098d52b/file.css",
332+
};
319333
const assets = [
320334
{
321335
path: ["**", "!**/*.txt", "!.dotfile"],
@@ -331,7 +345,7 @@ test.serial("Publish a release with asset type and permalink", async (t) => {
331345
links: [
332346
{
333347
name: uploaded.alt,
334-
url: `https://gitlab.com/${owner}/${repo}${uploaded.url}`,
348+
url: `https://gitlab.com${uploaded.full_path}`,
335349
link_type: uploaded.link_type,
336350
filepath: uploaded.filepath,
337351
},
@@ -346,7 +360,7 @@ test.serial("Publish a release with asset type and permalink", async (t) => {
346360
const result = await publish({ assets }, { env, cwd, options, nextRelease, logger: t.context.logger });
347361

348362
t.is(result.url, `https://gitlab.com/${owner}/${repo}/-/releases/${encodedGitTag}`);
349-
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", uploaded.url]);
363+
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", `https://gitlab.com${uploaded.full_path}`]);
350364
t.deepEqual(t.context.log.args[1], ["Published GitLab release: %s", nextRelease.gitTag]);
351365
t.true(gitlabUpload.isDone());
352366
t.true(gitlab.isDone());
@@ -361,7 +375,11 @@ test.serial("Publish a release with an asset with a template label", async (t) =
361375
const options = { repositoryUrl: `https://gitlab.com/${owner}/${repo}.git` };
362376
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
363377
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
364-
const uploaded = { url: "/uploads/file.css", alt: "file.css" };
378+
const uploaded = {
379+
url: "/uploads/file.css",
380+
alt: "file.css",
381+
full_path: "/-/project/4/66dbcd21ec5d24ed6ea225176098d52b/file.css",
382+
};
365383
const assets = [
366384
{
367385
label: `file-v\${nextRelease.version}.css`,
@@ -378,7 +396,7 @@ test.serial("Publish a release with an asset with a template label", async (t) =
378396
links: [
379397
{
380398
name: "file-v1.0.0.css",
381-
url: `https://gitlab.com/${owner}/${repo}${uploaded.url}`,
399+
url: `https://gitlab.com${uploaded.full_path}`,
382400
link_type: "other",
383401
filepath: "/dist/file.css",
384402
},
@@ -393,7 +411,7 @@ test.serial("Publish a release with an asset with a template label", async (t) =
393411
const result = await publish({ assets }, { env, cwd, options, nextRelease, logger: t.context.logger });
394412

395413
t.is(result.url, `https://gitlab.com/${owner}/${repo}/-/releases/${encodedGitTag}`);
396-
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", uploaded.url]);
414+
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", `https://gitlab.com${uploaded.full_path}`]);
397415
t.deepEqual(t.context.log.args[1], ["Published GitLab release: %s", nextRelease.gitTag]);
398416
t.true(gitlabUpload.isDone());
399417
t.true(gitlab.isDone());
@@ -410,7 +428,11 @@ test.serial("Publish a release (with an link) with variables", async (t) => {
410428
const options = { repositoryUrl: `https://gitlab.com/${owner}/${repo}.git` };
411429
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
412430
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
413-
const uploaded = { url: "/uploads/file.css", alt: "file.css" };
431+
const uploaded = {
432+
url: "/uploads/file.css",
433+
alt: "file.css",
434+
full_path: "/-/project/4/66dbcd21ec5d24ed6ea225176098d52b/file.css",
435+
};
414436
const assets = [
415437
{
416438
label: `README-v\${nextRelease.version}.md`,
@@ -437,7 +459,7 @@ test.serial("Publish a release (with an link) with variables", async (t) => {
437459
},
438460
{
439461
name: "file.css",
440-
url: `https://gitlab.com/${owner}/${repo}${uploaded.url}`,
462+
url: `https://gitlab.com${uploaded.full_path}`,
441463
link_type: "other",
442464
filepath: "/dist/file.css",
443465
},
@@ -452,7 +474,7 @@ test.serial("Publish a release (with an link) with variables", async (t) => {
452474
const result = await publish({ assets }, { env, cwd, options, nextRelease, logger: t.context.logger });
453475

454476
t.is(result.url, `https://gitlab.com/${owner}/${repo}/-/releases/${encodedGitTag}`);
455-
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", uploaded.url]);
477+
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", `https://gitlab.com${uploaded.full_path}`]);
456478
t.deepEqual(t.context.log.args[1], ["Published GitLab release: %s", nextRelease.gitTag]);
457479
t.true(gitlabUpload.isDone());
458480
t.true(gitlab.isDone());
@@ -524,7 +546,10 @@ test.serial("Publish a release with one asset and custom label", async (t) => {
524546
const options = { repositoryUrl: `https://gitlab.com/${owner}/${repo}.git` };
525547
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
526548
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
527-
const uploaded = { url: "/uploads/upload.txt" };
549+
const uploaded = {
550+
url: "/uploads/upload.txt",
551+
full_path: "/-/project/4/66dbcd21ec5d24ed6ea225176098d52b/upload.txt",
552+
};
528553
const assetLabel = "Custom Label";
529554
const assets = [{ path: "upload.txt", label: assetLabel }];
530555
const gitlab = authenticate(env)
@@ -535,7 +560,7 @@ test.serial("Publish a release with one asset and custom label", async (t) => {
535560
links: [
536561
{
537562
name: assetLabel,
538-
url: `https://gitlab.com/${owner}/${repo}${uploaded.url}`,
563+
url: `https://gitlab.com${uploaded.full_path}`,
539564
},
540565
],
541566
},
@@ -548,7 +573,7 @@ test.serial("Publish a release with one asset and custom label", async (t) => {
548573
const result = await publish({ assets }, { env, cwd, options, nextRelease, logger: t.context.logger });
549574

550575
t.is(result.url, `https://gitlab.com/${owner}/${repo}/-/releases/${encodedGitTag}`);
551-
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", uploaded.url]);
576+
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", `https://gitlab.com${uploaded.full_path}`]);
552577
t.deepEqual(t.context.log.args[1], ["Published GitLab release: %s", nextRelease.gitTag]);
553578
t.true(gitlabUpload.isDone());
554579
t.true(gitlab.isDone());

0 commit comments

Comments
 (0)