Skip to content

Commit

Permalink
feat: do not create Git tag anymore
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pvdlg committed Jan 27, 2018
1 parent 96d76d3 commit 111e894
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 78 deletions.
30 changes: 6 additions & 24 deletions lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,12 @@ module.exports = async (pluginConfig, {repositoryUrl}, {gitHead, gitTag, notes},
debug('release name: %o', gitTag);
debug('release ref: %o', gitHead);

try {
// Test if the tag already exists
await got.get(urlJoin(apiUrl, `/projects/${repoId}/repository/tags/${gitTag}`), {
json: true,
headers: {'Private-Token': gitlabToken},
});
debug('The git tag %o already exists, update the release description', gitTag);
// Update the release notes
await got.post(
urlJoin(apiUrl, `/projects/${repoId}/repository/tags/${gitTag}/release`),
{json: true, headers: {'Private-Token': gitlabToken}, body: {tag_name: gitTag, description: notes}} // eslint-disable-line camelcase
);
} catch (err) {
// If the error is 404, the tag doesn't exist, otherwise it's an error
if (err.statusCode !== 404) {
throw err;
}
debug('Create git tag %o with commit %o and release description', gitTag, gitHead);
await got.post(urlJoin(apiUrl, `/projects/${repoId}/repository/tags/${gitTag}/release`), {
json: true,
headers: {'PRIVATE-TOKEN': gitlabToken},
body: {tag_name: gitTag, ref: gitHead, release_description: notes}, // eslint-disable-line camelcase
});
}
debug('Update git tag %o with commit %o and release description', gitTag, gitHead);
await got.put(urlJoin(apiUrl, `/projects/${repoId}/repository/tags/${gitTag}/release`), {
json: true,
headers: {'PRIVATE-TOKEN': gitlabToken},
body: {tag_name: gitTag, ref: gitHead, release_description: notes}, // eslint-disable-line camelcase
});

logger.log('Published GitLab release: %s', gitTag);
};
5 changes: 1 addition & 4 deletions lib/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ module.exports = async (pluginConfig, {repositoryUrl}, logger) => {
debug('repoId: %o', repoId);

if (!repoId) {
throw new SemanticReleaseError(
`The git repository URL ${repositoryUrl} is not a valid GitLab URL.`,
'EINVALIDGITURL'
);
throw new SemanticReleaseError(`The git repository URL is not a valid GitLab URL.`, 'EINVALIDGITURL');
}

const apiUrl = urlJoin(gitlabUrl, gitlabApiPathPrefix);
Expand Down
8 changes: 2 additions & 6 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ test.serial('Publish a release', async t => {
const gitlab = authenticate()
.get(`/projects/${owner}%2F${repo}`)
.reply(200, {permissions: {project_access: {access_level: 30}}})
.get(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}`)
.reply(404)
.post(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}/release`, {
.put(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}/release`, {
tag_name: nextRelease.gitTag,
ref: nextRelease.gitHead,
release_description: nextRelease.notes,
Expand All @@ -83,9 +81,7 @@ test.serial('Verify Github auth and release', async t => {
const gitlab = authenticate()
.get(`/projects/${owner}%2F${repo}`)
.reply(200, {permissions: {project_access: {access_level: 30}}})
.get(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}`)
.reply(404)
.post(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}/release`, {
.put(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}/release`, {
tag_name: nextRelease.gitTag,
ref: nextRelease.gitHead,
release_description: nextRelease.notes,
Expand Down
45 changes: 1 addition & 44 deletions test/publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ test.serial('Publish a release', async t => {
const options = {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`};

const gitlab = authenticate()
.get(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}`)
.reply(404)
.post(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}/release`, {
.put(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}/release`, {
tag_name: nextRelease.gitTag,
ref: nextRelease.gitHead,
release_description: nextRelease.notes,
Expand All @@ -53,44 +51,3 @@ test.serial('Publish a release', async t => {
t.deepEqual(t.context.log.args[0], ['Published GitLab release: %s', nextRelease.gitTag]);
t.true(gitlab.isDone());
});

test.serial('Publish a release with an existing tag', async t => {
const owner = 'test_user';
const repo = 'test_repo';
process.env.GITLAB_TOKEN = 'gitlab_token';
const pluginConfig = {};
const nextRelease = {gitHead: '123', gitTag: 'v1.0.0', notes: 'Test release note body'};
const options = {branch: 'master', repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`};

const gitlab = authenticate()
.get(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}`)
.reply(200, {name: nextRelease.gitTag})
.post(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}/release`, {
tag_name: nextRelease.gitTag,
description: nextRelease.notes,
})
.reply(200);

await publish(pluginConfig, options, nextRelease, t.context.logger);

t.deepEqual(t.context.log.args[0], ['Published GitLab release: %s', nextRelease.gitTag]);
t.true(gitlab.isDone());
});

test.serial('Throw Error if get tag call return an error other than 404', async t => {
const owner = 'test_user';
const repo = 'test_repo';
process.env.GITLAB_TOKEN = 'github_token';
const pluginConfig = {};
const nextRelease = {gitHead: '123', gitTag: 'v1.0.0', notes: 'Test release note body'};
const options = {branch: 'master', repositoryUrl: `https://github.com/${owner}/${repo}.git`};

const github = authenticate()
.get(`/projects/${owner}%2F${repo}/repository/tags/${nextRelease.gitTag}`)
.reply(500);

const error = await t.throws(publish(pluginConfig, options, nextRelease, t.context.logger), Error);

t.is(error.statusCode, 500);
t.true(github.isDone());
});

0 comments on commit 111e894

Please sign in to comment.