Skip to content

Commit 111e894

Browse files
committed
feat: do not create Git tag anymore
BREAKING CHANGE: The Git tag is not created anymore The Git tag must be created by `semantic-release`. The plugin is compatible only with `semantic-release@13.0.0` or above.
1 parent 96d76d3 commit 111e894

File tree

4 files changed

+10
-78
lines changed

4 files changed

+10
-78
lines changed

lib/publish.js

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,12 @@ module.exports = async (pluginConfig, {repositoryUrl}, {gitHead, gitTag, notes},
1313
debug('release name: %o', gitTag);
1414
debug('release ref: %o', gitHead);
1515

16-
try {
17-
// Test if the tag already exists
18-
await got.get(urlJoin(apiUrl, `/projects/${repoId}/repository/tags/${gitTag}`), {
19-
json: true,
20-
headers: {'Private-Token': gitlabToken},
21-
});
22-
debug('The git tag %o already exists, update the release description', gitTag);
23-
// Update the release notes
24-
await got.post(
25-
urlJoin(apiUrl, `/projects/${repoId}/repository/tags/${gitTag}/release`),
26-
{json: true, headers: {'Private-Token': gitlabToken}, body: {tag_name: gitTag, description: notes}} // eslint-disable-line camelcase
27-
);
28-
} catch (err) {
29-
// If the error is 404, the tag doesn't exist, otherwise it's an error
30-
if (err.statusCode !== 404) {
31-
throw err;
32-
}
33-
debug('Create git tag %o with commit %o and release description', gitTag, gitHead);
34-
await got.post(urlJoin(apiUrl, `/projects/${repoId}/repository/tags/${gitTag}/release`), {
35-
json: true,
36-
headers: {'PRIVATE-TOKEN': gitlabToken},
37-
body: {tag_name: gitTag, ref: gitHead, release_description: notes}, // eslint-disable-line camelcase
38-
});
39-
}
16+
debug('Update git tag %o with commit %o and release description', gitTag, gitHead);
17+
await got.put(urlJoin(apiUrl, `/projects/${repoId}/repository/tags/${gitTag}/release`), {
18+
json: true,
19+
headers: {'PRIVATE-TOKEN': gitlabToken},
20+
body: {tag_name: gitTag, ref: gitHead, release_description: notes}, // eslint-disable-line camelcase
21+
});
4022

4123
logger.log('Published GitLab release: %s', gitTag);
4224
};

lib/verify.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ module.exports = async (pluginConfig, {repositoryUrl}, logger) => {
1717
debug('repoId: %o', repoId);
1818

1919
if (!repoId) {
20-
throw new SemanticReleaseError(
21-
`The git repository URL ${repositoryUrl} is not a valid GitLab URL.`,
22-
'EINVALIDGITURL'
23-
);
20+
throw new SemanticReleaseError(`The git repository URL is not a valid GitLab URL.`, 'EINVALIDGITURL');
2421
}
2522

2623
const apiUrl = urlJoin(gitlabUrl, gitlabApiPathPrefix);

test/integration.test.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ test.serial('Publish a release', async t => {
5757
const gitlab = authenticate()
5858
.get(`/projects/${owner}%2F${repo}`)
5959
.reply(200, {permissions: {project_access: {access_level: 30}}})
60-
.get(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}`)
61-
.reply(404)
62-
.post(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}/release`, {
60+
.put(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}/release`, {
6361
tag_name: nextRelease.gitTag,
6462
ref: nextRelease.gitHead,
6563
release_description: nextRelease.notes,
@@ -83,9 +81,7 @@ test.serial('Verify Github auth and release', async t => {
8381
const gitlab = authenticate()
8482
.get(`/projects/${owner}%2F${repo}`)
8583
.reply(200, {permissions: {project_access: {access_level: 30}}})
86-
.get(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}`)
87-
.reply(404)
88-
.post(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}/release`, {
84+
.put(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}/release`, {
8985
tag_name: nextRelease.gitTag,
9086
ref: nextRelease.gitHead,
9187
release_description: nextRelease.notes,

test/publish.test.js

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ test.serial('Publish a release', async t => {
3939
const options = {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`};
4040

4141
const gitlab = authenticate()
42-
.get(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}`)
43-
.reply(404)
44-
.post(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}/release`, {
42+
.put(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}/release`, {
4543
tag_name: nextRelease.gitTag,
4644
ref: nextRelease.gitHead,
4745
release_description: nextRelease.notes,
@@ -53,44 +51,3 @@ test.serial('Publish a release', async t => {
5351
t.deepEqual(t.context.log.args[0], ['Published GitLab release: %s', nextRelease.gitTag]);
5452
t.true(gitlab.isDone());
5553
});
56-
57-
test.serial('Publish a release with an existing tag', async t => {
58-
const owner = 'test_user';
59-
const repo = 'test_repo';
60-
process.env.GITLAB_TOKEN = 'gitlab_token';
61-
const pluginConfig = {};
62-
const nextRelease = {gitHead: '123', gitTag: 'v1.0.0', notes: 'Test release note body'};
63-
const options = {branch: 'master', repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`};
64-
65-
const gitlab = authenticate()
66-
.get(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}`)
67-
.reply(200, {name: nextRelease.gitTag})
68-
.post(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}/release`, {
69-
tag_name: nextRelease.gitTag,
70-
description: nextRelease.notes,
71-
})
72-
.reply(200);
73-
74-
await publish(pluginConfig, options, nextRelease, t.context.logger);
75-
76-
t.deepEqual(t.context.log.args[0], ['Published GitLab release: %s', nextRelease.gitTag]);
77-
t.true(gitlab.isDone());
78-
});
79-
80-
test.serial('Throw Error if get tag call return an error other than 404', async t => {
81-
const owner = 'test_user';
82-
const repo = 'test_repo';
83-
process.env.GITLAB_TOKEN = 'github_token';
84-
const pluginConfig = {};
85-
const nextRelease = {gitHead: '123', gitTag: 'v1.0.0', notes: 'Test release note body'};
86-
const options = {branch: 'master', repositoryUrl: `https://github.com/${owner}/${repo}.git`};
87-
88-
const github = authenticate()
89-
.get(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}`)
90-
.reply(500);
91-
92-
const error = await t.throws(publish(pluginConfig, options, nextRelease, t.context.logger), Error);
93-
94-
t.is(error.statusCode, 500);
95-
t.true(github.isDone());
96-
});

0 commit comments

Comments
 (0)