Skip to content

Commit 04cdfed

Browse files
constantologypvdlg
authored andcommitted
fix(publish): encode git tag in API URI
1 parent e08a1c2 commit 04cdfed

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/publish.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@ module.exports = async (pluginConfig, {options: {repositoryUrl}, nextRelease: {g
88
const {gitlabToken, gitlabUrl, gitlabApiPathPrefix} = resolveConfig(pluginConfig);
99
const repoId = getRepoId(gitlabUrl, repositoryUrl);
1010
const apiUrl = urlJoin(gitlabUrl, gitlabApiPathPrefix);
11+
const gitTagEncoded = encodeURIComponent(gitTag);
1112

1213
debug('repoId: %o', repoId);
1314
debug('release name: %o', gitTag);
1415
debug('release ref: %o', gitHead);
1516

1617
debug('Update git tag %o with commit %o and release description', gitTag, gitHead);
17-
await got.post(urlJoin(apiUrl, `/projects/${encodeURIComponent(repoId)}/repository/tags/${gitTag}/release`), {
18+
await got.post(urlJoin(apiUrl, `/projects/${encodeURIComponent(repoId)}/repository/tags/${gitTagEncoded}/release`), {
1819
json: true,
1920
headers: {'PRIVATE-TOKEN': gitlabToken},
2021
body: {tag_name: gitTag, description: notes}, // eslint-disable-line camelcase
2122
});
2223

2324
logger.log('Published GitLab release: %s', gitTag);
2425

25-
return {url: urlJoin(gitlabUrl, repoId, `/tags/${gitTag}`), name: 'GitHub release'};
26+
return {url: urlJoin(gitlabUrl, repoId, `/tags/${gitTagEncoded}`), name: 'GitHub release'};
2627
};

test/publish.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,20 @@ test.serial('Publish a release', async t => {
3535
const repo = 'test_repo';
3636
process.env.GITLAB_TOKEN = 'gitlab_token';
3737
const pluginConfig = {};
38-
const nextRelease = {gitHead: '123', gitTag: 'v1.0.0', notes: 'Test release note body'};
38+
const nextRelease = {gitHead: '123', gitTag: '@scope/v1.0.0', notes: 'Test release note body'};
3939
const options = {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`};
40+
const gitTagEncoded = encodeURIComponent(nextRelease.gitTag);
4041

4142
const gitlab = authenticate()
42-
.post(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}/release`, {
43+
.post(`/projects/${owner}%2F${repo}/repository/tags/${gitTagEncoded}/release`, {
4344
tag_name: nextRelease.gitTag,
4445
description: nextRelease.notes,
4546
})
4647
.reply(200);
4748

4849
const result = await publish(pluginConfig, {options, nextRelease, logger: t.context.logger});
4950

50-
t.is(result.url, `https://gitlab.com/${owner}/${repo}/tags/${nextRelease.gitTag}`);
51+
t.is(result.url, `https://gitlab.com/${owner}/${repo}/tags/${gitTagEncoded}`);
5152
t.deepEqual(t.context.log.args[0], ['Published GitLab release: %s', nextRelease.gitTag]);
5253
t.true(gitlab.isDone());
5354
});

0 commit comments

Comments
 (0)