Skip to content

Commit 18d09c2

Browse files
authored
Merge pull request #630 from mattyclarkson/patch-1
feat: templating of `path`
2 parents 8fbd955 + da6ecc3 commit 18d09c2

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Can be a [glob](https://github.com/isaacs/node-glob#glob-primer) or and `Array`
101101

102102
| Property | Description | Default |
103103
| ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
104-
| `path` | **Required**, unless `url` is set. A [glob](https://github.com/isaacs/node-glob#glob-primer) to identify the files to upload. | - |
104+
| `path` | **Required**, unless `url` is set. A [glob](https://github.com/isaacs/node-glob#glob-primer) to identify the files to upload. Supports [Lodash templating](https://lodash.com/docs#template). | - |
105105
| `url` | Alternative to setting `path` this provides the ability to add links to releases, e.g. URLs to container images. Supports [Lodash templating](https://lodash.com/docs#template). | - |
106106
| `label` | Short description of the file displayed on the GitLab release. Ignored if `path` matches more than one file. Supports [Lodash templating](https://lodash.com/docs#template). | File name extracted from the `path`. |
107107
| `type` | Asset type displayed on the GitLab release. Can be `runbook`, `package`, `image` and `other` (see official documents on [release assets](https://docs.gitlab.com/ee/user/project/releases/#release-assets)). Supports [Lodash templating](https://lodash.com/docs#template). | `other` |

lib/publish.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default async (pluginConfig, context) => {
4848

4949
await Promise.all(
5050
allAssets.map(async (asset) => {
51-
const { path } = isPlainObject(asset) ? asset : { path: asset };
51+
const path = template((isPlainObject(asset) ? asset : { path: asset }).path)(context);
5252
const _url = asset.url ? template(asset.url)(context) : undefined;
5353
const label = asset.label ? template(asset.label)(context) : undefined;
5454
const type = asset.type ? template(asset.type)(context) : undefined;

test/publish.test.js

+39
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,45 @@ test.serial("Publish a release", async (t) => {
4545
t.true(gitlab.isDone());
4646
});
4747

48+
test.serial("Publish a release with templated path", async (t) => {
49+
const cwd = "test/fixtures/files";
50+
const owner = "test_user";
51+
const repo = "test_repo";
52+
const env = { GITLAB_TOKEN: "gitlab_token", FIXTURE: "upload" };
53+
const nextRelease = { gitHead: "123", gitTag: "v1.0.0", notes: "Test release note body" };
54+
const options = { repositoryUrl: `https://gitlab.com/${owner}/${repo}.git` };
55+
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
56+
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
57+
const generic = { path: "${env.FIXTURE}.txt", filepath: "/upload.txt" };
58+
const assets = [generic];
59+
const uploaded = { url: "/uploads/upload.txt", alt: "upload.txt" };
60+
const gitlab = authenticate(env)
61+
.post(`/projects/${encodedRepoId}/releases`, {
62+
tag_name: nextRelease.gitTag,
63+
description: nextRelease.notes,
64+
assets: {
65+
links: [
66+
{
67+
name: "upload.txt",
68+
url: `https://gitlab.com/${owner}/${repo}${uploaded.url}`,
69+
filepath: "/upload.txt",
70+
},
71+
],
72+
},
73+
})
74+
.reply(200);
75+
const gitlabUpload = authenticate(env)
76+
.post(`/projects/${encodedRepoId}/uploads`, /Content-Disposition/g)
77+
.reply(200, uploaded);
78+
79+
const result = await publish({ assets }, { env, cwd, options, nextRelease, logger: t.context.logger });
80+
81+
t.is(result.url, `https://gitlab.com/${owner}/${repo}/-/releases/${encodedGitTag}`);
82+
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", uploaded.url]);
83+
t.deepEqual(t.context.log.args[1], ["Published GitLab release: %s", nextRelease.gitTag]);
84+
t.true(gitlab.isDone());
85+
});
86+
4887
test.serial("Publish a release with assets", async (t) => {
4988
const cwd = "test/fixtures/files";
5089
const owner = "test_user";

0 commit comments

Comments
 (0)