diff --git a/lib/publish.js b/lib/publish.js index 19e03293..7bbce2a5 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -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); @@ -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); @@ -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, diff --git a/test/integration.test.js b/test/integration.test.js index 4a76dcdc..0e360c7a 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -58,7 +58,7 @@ 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}`); @@ -66,6 +66,7 @@ test.serial('Publish a release', async t => { .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: { @@ -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: { diff --git a/test/publish.test.js b/test/publish.test.js index af1f795b..2c89d9af 100644 --- a/test/publish.test.js +++ b/test/publish.test.js @@ -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: { @@ -50,7 +51,7 @@ 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); @@ -58,6 +59,7 @@ test.serial('Publish a release with assets', async t => { const assets = [['**', '!**/*.txt', '!.dotfile']]; const gitlab = authenticate(env) .post(`/projects/${encodedRepoId}/releases`, { + name: nextRelease.name, tag_name: nextRelease.gitTag, description: nextRelease.notes, assets: { @@ -161,7 +163,7 @@ 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); @@ -169,6 +171,7 @@ test.serial('Publish a release with array of missing assets', async t => { 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: { @@ -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); @@ -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: { @@ -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'}; @@ -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: {