Skip to content

fix(publish): Compatible with older versions of GitLab, lack of "name" attribu… #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = async (pluginConfig, context) => {
const {
cwd,
options: {repositoryUrl},
nextRelease: {gitTag, gitHead, notes},
nextRelease: {gitTag, name, gitHead, notes},
logger,
} = context;
const {gitlabToken, gitlabUrl, gitlabApiUrl, assets, milestones} = resolveConfig(pluginConfig, context);
Expand All @@ -25,7 +25,8 @@ module.exports = async (pluginConfig, context) => {
const apiOptions = {headers: {'PRIVATE-TOKEN': gitlabToken}};

debug('repoId: %o', repoId);
debug('release name: %o', gitTag);
debug('release name: %o', name);
debug('release gitTag: %o', gitTag);
debug('release ref: %o', gitHead);
debug('milestones: %o', milestones);

Expand Down Expand Up @@ -75,6 +76,7 @@ module.exports = async (pluginConfig, context) => {
...apiOptions,
json: {
/* eslint-disable camelcase */
name: name ? name : gitTag,
tag_name: gitTag,
description: notes && notes.trim() ? notes : gitTag,
milestones,
Expand Down
6 changes: 4 additions & 2 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ test.serial('Publish a release', async t => {
const owner = 'test_user';
const repo = 'test_repo';
const env = {GL_TOKEN: 'gitlab_token'};
const nextRelease = {gitHead: '123', gitTag: 'v1.0.0', notes: 'Test release note body'};
const nextRelease = {gitHead: '123', name: 'v1.0.0', gitTag: 'v1.0.0', notes: 'Test release note body'};
const options = {branch: 'master', repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`};
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);

const gitlab = authenticate(env)
.get(`/projects/${encodedRepoId}`)
.reply(200, {permissions: {project_access: {access_level: 30}}})
.post(`/projects/${encodedRepoId}/releases`, {
name: nextRelease.name || nextRelease.gitTag,
tag_name: nextRelease.gitTag,
description: nextRelease.notes,
assets: {
Expand All @@ -88,12 +89,13 @@ test.serial('Verify Github auth and release', async t => {
const repo = 'test_repo';
const options = {repositoryUrl: `https://github.com/${owner}/${repo}.git`};
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
const nextRelease = {gitHead: '123', gitTag: 'v1.0.0', notes: 'Test release note body'};
const nextRelease = {gitHead: '123', name: 'v1.0.0', gitTag: 'v1.0.0', notes: 'Test release note body'};

const gitlab = authenticate(env)
.get(`/projects/${encodedRepoId}`)
.reply(200, {permissions: {project_access: {access_level: 30}}})
.post(`/projects/${encodedRepoId}/releases`, {
name: nextRelease.name,
tag_name: nextRelease.gitTag,
description: nextRelease.notes,
assets: {
Expand Down
40 changes: 36 additions & 4 deletions test/publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ test.serial('Publish a release', async t => {
const repo = 'test_repo';
const env = {GITLAB_TOKEN: 'gitlab_token'};
const pluginConfig = {};
const nextRelease = {gitHead: '123', gitTag: 'v1.0.0', notes: 'Test release note body'};
const nextRelease = {gitHead: '123', name: 'v1.0.0', gitTag: 'v1.0.0', notes: 'Test release note body'};
const options = {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`};
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
const gitlab = authenticate(env)
.post(`/projects/${encodedRepoId}/releases`, {
name: nextRelease.name,
tag_name: nextRelease.gitTag,
description: nextRelease.notes,
assets: {
Expand All @@ -50,14 +51,15 @@ test.serial('Publish a release with assets', async t => {
const owner = 'test_user';
const repo = 'test_repo';
const env = {GITLAB_TOKEN: 'gitlab_token'};
const nextRelease = {gitHead: '123', gitTag: 'v1.0.0', notes: 'Test release note body'};
const nextRelease = {gitHead: '123', name: 'v1.0.0', gitTag: 'v1.0.0', notes: 'Test release note body'};
const options = {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`};
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
const uploaded = {url: '/uploads/file.css', alt: 'file.css'};
const assets = [['**', '!**/*.txt', '!.dotfile']];
const gitlab = authenticate(env)
.post(`/projects/${encodedRepoId}/releases`, {
name: nextRelease.name,
tag_name: nextRelease.gitTag,
description: nextRelease.notes,
assets: {
Expand Down Expand Up @@ -161,14 +163,15 @@ test.serial('Publish a release with array of missing assets', async t => {
const owner = 'test_user';
const repo = 'test_repo';
const env = {GITLAB_TOKEN: 'gitlab_token'};
const nextRelease = {gitHead: '123', gitTag: 'v1.0.0', notes: 'Test release note body'};
const nextRelease = {gitHead: '123', name: 'v1.0.0', gitTag: 'v1.0.0', notes: 'Test release note body'};
const options = {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`};
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
const emptyDirectory = tempy.directory();
const assets = [emptyDirectory, {path: 'missing.txt', label: 'missing.txt'}];
const gitlab = authenticate(env)
.post(`/projects/${encodedRepoId}/releases`, {
name: nextRelease.name,
tag_name: nextRelease.gitTag,
description: nextRelease.notes,
assets: {
Expand All @@ -188,7 +191,7 @@ test.serial('Publish a release with one asset and custom label', async t => {
const owner = 'test_user';
const repo = 'test_repo';
const env = {GITLAB_TOKEN: 'gitlab_token'};
const nextRelease = {gitHead: '123', gitTag: 'v1.0.0', notes: 'Test release note body'};
const nextRelease = {gitHead: '123', name: 'v1.0.0', gitTag: 'v1.0.0', notes: 'Test release note body'};
const options = {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`};
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
Expand All @@ -197,6 +200,7 @@ test.serial('Publish a release with one asset and custom label', async t => {
const assets = [{path: 'upload.txt', label: assetLabel}];
const gitlab = authenticate(env)
.post(`/projects/${encodedRepoId}/releases`, {
name: nextRelease.name,
tag_name: nextRelease.gitTag,
description: nextRelease.notes,
assets: {
Expand All @@ -223,6 +227,33 @@ test.serial('Publish a release with one asset and custom label', async t => {
});

test.serial('Publish a release with missing release notes', async t => {
const owner = 'test_user';
const repo = 'test_repo';
const env = {GITLAB_TOKEN: 'gitlab_token'};
const pluginConfig = {};
const nextRelease = {gitHead: '123', name: 'v1.0.0', gitTag: 'v1.0.0'};
const options = {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`};
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
const gitlab = authenticate(env)
.post(`/projects/${encodedRepoId}/releases`, {
name: nextRelease.name,
tag_name: nextRelease.gitTag,
description: nextRelease.gitTag,
assets: {
links: [],
},
})
.reply(200);

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

t.is(result.url, `https://gitlab.com/${encodedRepoId}/-/releases/${encodedGitTag}`);
t.deepEqual(t.context.log.args[0], ['Published GitLab release: %s', nextRelease.gitTag]);
t.true(gitlab.isDone());
});

test.serial('Publish a release with missing name', async t => {
const owner = 'test_user';
const repo = 'test_repo';
const env = {GITLAB_TOKEN: 'gitlab_token'};
Expand All @@ -233,6 +264,7 @@ test.serial('Publish a release with missing release notes', async t => {
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
const gitlab = authenticate(env)
.post(`/projects/${encodedRepoId}/releases`, {
name: nextRelease.name || nextRelease.gitTag,
tag_name: nextRelease.gitTag,
description: nextRelease.gitTag,
assets: {
Expand Down