Skip to content

Commit 852dd42

Browse files
committed
fix: encode repoid in release URL returned by publish
1 parent 04cdfed commit 852dd42

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

lib/publish.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@ const getRepoId = require('./get-repo-id');
77
module.exports = async (pluginConfig, {options: {repositoryUrl}, nextRelease: {gitTag, gitHead, notes}, logger}) => {
88
const {gitlabToken, gitlabUrl, gitlabApiPathPrefix} = resolveConfig(pluginConfig);
99
const repoId = getRepoId(gitlabUrl, repositoryUrl);
10+
const encodedRepoId = encodeURIComponent(repoId);
1011
const apiUrl = urlJoin(gitlabUrl, gitlabApiPathPrefix);
11-
const gitTagEncoded = encodeURIComponent(gitTag);
12+
const encodedGitTag = encodeURIComponent(gitTag);
1213

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

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

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

26-
return {url: urlJoin(gitlabUrl, repoId, `/tags/${gitTagEncoded}`), name: 'GitHub release'};
27+
return {url: urlJoin(gitlabUrl, encodedRepoId, `/tags/${encodedGitTag}`), name: 'GitHub release'};
2728
};

test/integration.test.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,20 @@ test.serial('Publish a release', async t => {
7171
process.env.GL_TOKEN = 'gitlab_token';
7272
const nextRelease = {gitHead: '123', gitTag: 'v1.0.0', notes: 'Test release note body'};
7373
const options = {branch: 'master', repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`};
74+
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
7475

7576
const gitlab = authenticate()
76-
.get(`/projects/${owner}%2F${repo}`)
77+
.get(`/projects/${encodedRepoId}`)
7778
.reply(200, {permissions: {project_access: {access_level: 30}}})
78-
.post(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}/release`, {
79+
.post(`/projects/${encodedRepoId}/repository/tags/${nextRelease.gitTag}/release`, {
7980
tag_name: nextRelease.gitTag,
8081
description: nextRelease.notes,
8182
})
8283
.reply(200);
8384

8485
const result = await t.context.m.publish({}, {nextRelease, options, logger: t.context.logger});
8586

86-
t.is(result.url, `https://gitlab.com/${owner}/${repo}/tags/${nextRelease.gitTag}`);
87+
t.is(result.url, `https://gitlab.com/${encodedRepoId}/tags/${nextRelease.gitTag}`);
8788
t.deepEqual(t.context.log.args[0], ['Verify GitLab authentication (%s)', 'https://gitlab.com/api/v4']);
8889
t.deepEqual(t.context.log.args[1], ['Published GitLab release: %s', nextRelease.gitTag]);
8990
t.true(gitlab.isDone());
@@ -94,12 +95,13 @@ test.serial('Verify Github auth and release', async t => {
9495
const owner = 'test_user';
9596
const repo = 'test_repo';
9697
const options = {repositoryUrl: `https://github.com/${owner}/${repo}.git`};
98+
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
9799
const nextRelease = {gitHead: '123', gitTag: 'v1.0.0', notes: 'Test release note body'};
98100

99101
const gitlab = authenticate()
100-
.get(`/projects/${owner}%2F${repo}`)
102+
.get(`/projects/${encodedRepoId}`)
101103
.reply(200, {permissions: {project_access: {access_level: 30}}})
102-
.post(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}/release`, {
104+
.post(`/projects/${encodedRepoId}/repository/tags/${nextRelease.gitTag}/release`, {
103105
tag_name: nextRelease.gitTag,
104106
description: nextRelease.notes,
105107
})
@@ -108,7 +110,7 @@ test.serial('Verify Github auth and release', async t => {
108110
await t.notThrows(t.context.m.verifyConditions({}, {options, logger: t.context.logger}));
109111
const result = await t.context.m.publish({}, {nextRelease, options, logger: t.context.logger});
110112

111-
t.is(result.url, `https://gitlab.com/${owner}/${repo}/tags/${nextRelease.gitTag}`);
113+
t.is(result.url, `https://gitlab.com/${encodedRepoId}/tags/${nextRelease.gitTag}`);
112114
t.deepEqual(t.context.log.args[0], ['Verify GitLab authentication (%s)', 'https://gitlab.com/api/v4']);
113115
t.deepEqual(t.context.log.args[1], ['Published GitLab release: %s', nextRelease.gitTag]);
114116
t.true(gitlab.isDone());

test/publish.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,19 @@ test.serial('Publish a release', async t => {
3737
const pluginConfig = {};
3838
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);
40+
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
41+
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
4142

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

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

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

0 commit comments

Comments
 (0)