Skip to content

Commit f82b613

Browse files
author
Nathan Friend
authored
fix: replace deprecated Tags API call (#184) thanks @nfriend
This commit replaces calls to the deprecated Tags API endpoints with equivalent calls to the Releases API.
1 parent ff48a65 commit f82b613

File tree

3 files changed

+55
-37
lines changed

3 files changed

+55
-37
lines changed

lib/publish.js

+16-15
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,25 @@ module.exports = async (pluginConfig, context) => {
6767
);
6868
}
6969

70-
debug('Update git tag %o with commit %o and release description', gitTag, gitHead);
71-
await got.post(urlJoin(gitlabApiUrl, `/projects/${encodedRepoId}/repository/tags/${encodedGitTag}/release`), {
70+
debug('Create a release for git tag %o with commit %o', gitTag, gitHead);
71+
await got.post(urlJoin(gitlabApiUrl, `/projects/${encodedRepoId}/releases`), {
7272
...apiOptions,
73-
json: {tag_name: gitTag, description: notes && notes.trim() ? notes : gitTag}, // eslint-disable-line camelcase
73+
json: {
74+
/* eslint-disable camelcase */
75+
tag_name: gitTag,
76+
description: notes && notes.trim() ? notes : gitTag,
77+
assets: {
78+
links: assetsList.map(({label, alt, url}) => {
79+
return {
80+
name: label || alt,
81+
url: urlJoin(gitlabUrl, repoId, url),
82+
};
83+
}),
84+
},
85+
/* eslint-enable camelcase */
86+
},
7487
});
7588

76-
if (assetsList.length > 0) {
77-
await Promise.all(
78-
assetsList.map(({label, alt, url}) => {
79-
debug('Add link to asset %o', label || alt);
80-
return got.post(urlJoin(gitlabApiUrl, `/projects/${encodedRepoId}/releases/${encodedGitTag}/assets/links`), {
81-
...apiOptions,
82-
json: {name: label || alt, url: urlJoin(gitlabUrl, repoId, url)},
83-
});
84-
})
85-
);
86-
}
87-
8889
logger.log('Published GitLab release: %s', gitTag);
8990

9091
return {url: urlJoin(gitlabUrl, encodedRepoId, `/tags/${encodedGitTag}`), name: 'GitLab release'};

test/integration.test.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ test.serial('Publish a release', async t => {
6565
const gitlab = authenticate(env)
6666
.get(`/projects/${encodedRepoId}`)
6767
.reply(200, {permissions: {project_access: {access_level: 30}}})
68-
.post(`/projects/${encodedRepoId}/repository/tags/${nextRelease.gitTag}/release`, {
68+
.post(`/projects/${encodedRepoId}/releases`, {
6969
tag_name: nextRelease.gitTag,
7070
description: nextRelease.notes,
71+
assets: {
72+
links: [],
73+
},
7174
})
7275
.reply(200);
7376

@@ -90,9 +93,12 @@ test.serial('Verify Github auth and release', async t => {
9093
const gitlab = authenticate(env)
9194
.get(`/projects/${encodedRepoId}`)
9295
.reply(200, {permissions: {project_access: {access_level: 30}}})
93-
.post(`/projects/${encodedRepoId}/repository/tags/${nextRelease.gitTag}/release`, {
96+
.post(`/projects/${encodedRepoId}/releases`, {
9497
tag_name: nextRelease.gitTag,
9598
description: nextRelease.notes,
99+
assets: {
100+
links: [],
101+
},
96102
})
97103
.reply(200);
98104

test/publish.test.js

+31-20
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ test.serial('Publish a release', async t => {
2929
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
3030
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
3131
const gitlab = authenticate(env)
32-
.post(`/projects/${encodedRepoId}/repository/tags/${encodedGitTag}/release`, {
32+
.post(`/projects/${encodedRepoId}/releases`, {
3333
tag_name: nextRelease.gitTag,
3434
description: nextRelease.notes,
35+
assets: {
36+
links: [],
37+
},
3538
})
3639
.reply(200);
3740

@@ -54,20 +57,22 @@ test.serial('Publish a release with assets', async t => {
5457
const uploaded = {url: '/uploads/file.css', alt: 'file.css'};
5558
const assets = [['**', '!**/*.txt', '!.dotfile']];
5659
const gitlab = authenticate(env)
57-
.post(`/projects/${encodedRepoId}/repository/tags/${encodedGitTag}/release`, {
60+
.post(`/projects/${encodedRepoId}/releases`, {
5861
tag_name: nextRelease.gitTag,
5962
description: nextRelease.notes,
63+
assets: {
64+
links: [
65+
{
66+
name: uploaded.alt,
67+
url: `https://gitlab.com/${owner}/${repo}${uploaded.url}`,
68+
},
69+
],
70+
},
6071
})
6172
.reply(200);
6273
const gitlabUpload = authenticate(env)
6374
.post(`/projects/${encodedRepoId}/uploads`, /filename="file.css"/gm)
6475
.reply(200, uploaded);
65-
const gitlabAssetLink = authenticate(env)
66-
.post(`/projects/${encodedRepoId}/releases/${encodedGitTag}/assets/links`, {
67-
url: `https://gitlab.com/${owner}/${repo}${uploaded.url}`,
68-
name: uploaded.alt,
69-
})
70-
.reply(200, {});
7176

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

@@ -76,7 +81,6 @@ test.serial('Publish a release with assets', async t => {
7681
t.deepEqual(t.context.log.args[1], ['Published GitLab release: %s', nextRelease.gitTag]);
7782
t.true(gitlabUpload.isDone());
7883
t.true(gitlab.isDone());
79-
t.true(gitlabAssetLink.isDone());
8084
});
8185

8286
test.serial('Publish a release with array of missing assets', async t => {
@@ -91,9 +95,12 @@ test.serial('Publish a release with array of missing assets', async t => {
9195
const emptyDirectory = tempy.directory();
9296
const assets = [emptyDirectory, {path: 'missing.txt', label: 'missing.txt'}];
9397
const gitlab = authenticate(env)
94-
.post(`/projects/${encodedRepoId}/repository/tags/${encodedGitTag}/release`, {
98+
.post(`/projects/${encodedRepoId}/releases`, {
9599
tag_name: nextRelease.gitTag,
96100
description: nextRelease.notes,
101+
assets: {
102+
links: [],
103+
},
97104
})
98105
.reply(200);
99106
const result = await publish({assets}, {env, cwd, options, nextRelease, logger: t.context.logger});
@@ -116,20 +123,22 @@ test.serial('Publish a release with one asset and custom label', async t => {
116123
const assetLabel = 'Custom Label';
117124
const assets = [{path: 'upload.txt', label: assetLabel}];
118125
const gitlab = authenticate(env)
119-
.post(`/projects/${encodedRepoId}/repository/tags/${encodedGitTag}/release`, {
126+
.post(`/projects/${encodedRepoId}/releases`, {
120127
tag_name: nextRelease.gitTag,
121128
description: nextRelease.notes,
129+
assets: {
130+
links: [
131+
{
132+
name: assetLabel,
133+
url: `https://gitlab.com/${owner}/${repo}${uploaded.url}`,
134+
},
135+
],
136+
},
122137
})
123138
.reply(200);
124139
const gitlabUpload = authenticate(env)
125140
.post(`/projects/${encodedRepoId}/uploads`, /filename="upload.txt"/gm)
126141
.reply(200, uploaded);
127-
const gitlabAssetLink = authenticate(env)
128-
.post(`/projects/${encodedRepoId}/releases/${encodedGitTag}/assets/links`, {
129-
url: `https://gitlab.com/${owner}/${repo}${uploaded.url}`,
130-
name: assetLabel,
131-
})
132-
.reply(200, {});
133142

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

@@ -138,10 +147,9 @@ test.serial('Publish a release with one asset and custom label', async t => {
138147
t.deepEqual(t.context.log.args[1], ['Published GitLab release: %s', nextRelease.gitTag]);
139148
t.true(gitlabUpload.isDone());
140149
t.true(gitlab.isDone());
141-
t.true(gitlabAssetLink.isDone());
142150
});
143151

144-
test.serial('Publish a release with missing releasae notes', async t => {
152+
test.serial('Publish a release with missing release notes', async t => {
145153
const owner = 'test_user';
146154
const repo = 'test_repo';
147155
const env = {GITLAB_TOKEN: 'gitlab_token'};
@@ -151,9 +159,12 @@ test.serial('Publish a release with missing releasae notes', async t => {
151159
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
152160
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
153161
const gitlab = authenticate(env)
154-
.post(`/projects/${encodedRepoId}/repository/tags/${encodedGitTag}/release`, {
162+
.post(`/projects/${encodedRepoId}/releases`, {
155163
tag_name: nextRelease.gitTag,
156164
description: nextRelease.gitTag,
165+
assets: {
166+
links: [],
167+
},
157168
})
158169
.reply(200);
159170

0 commit comments

Comments
 (0)