Skip to content

Commit

Permalink
fix: link_type default to undefined and fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
yxonic committed Jun 5, 2021
1 parent 961dd6e commit 732a34f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = async (pluginConfig, context) => {
return {
name: label || alt,
url: urlJoin(gitlabUrl, repoId, url),
link_type: type || 'other',
link_type: type,
filepath,
};
}),
Expand Down
46 changes: 46 additions & 0 deletions test/publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,52 @@ test.serial('Publish a release with assets', async t => {
t.true(gitlab.isDone());
});

test.serial('Publish a release with asset type and permalink', async t => {
const cwd = 'test/fixtures/files';
const owner = 'test_user';
const repo = 'test_repo';
const env = {GITLAB_TOKEN: 'gitlab_token'};
const nextRelease = {gitHead: '123', gitTag: 'v1.0.0', notes: 'Test release note body'};
const options = {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`};
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
const uploaded = {url: '/uploads/file.css', alt: 'file.css', link_type: 'package', filepath: '/dist/file.css'};
const assets = [
{
path: 'file.css',
type: 'package',
filepath: '/dist/file.css',
},
];
const gitlab = authenticate(env)
.post(`/projects/${encodedRepoId}/releases`, {
tag_name: nextRelease.gitTag,
description: nextRelease.notes,
assets: {
links: [
{
name: uploaded.alt,
url: `https://gitlab.com/${owner}/${repo}${uploaded.url}`,
link_type: uploaded.link_type,
filepath: uploaded.filepath,
},
],
},
})
.reply(200);
const gitlabUpload = authenticate(env)
.post(`/projects/${encodedRepoId}/uploads`, /filename="file.css"/gm)
.reply(200, uploaded);

const result = await publish({assets}, {env, cwd, options, nextRelease, logger: t.context.logger});

t.is(result.url, `https://gitlab.com/${encodedRepoId}/-/releases/${encodedGitTag}`);
t.deepEqual(t.context.log.args[0], ['Uploaded file: %s', uploaded.url]);
t.deepEqual(t.context.log.args[1], ['Published GitLab release: %s', nextRelease.gitTag]);
t.true(gitlabUpload.isDone());
t.true(gitlab.isDone());
});

test.serial('Publish a release with a milestone', async t => {
const owner = 'test_user';
const repo = 'test_repo';
Expand Down

0 comments on commit 732a34f

Please sign in to comment.