diff --git a/README.md b/README.md index 1b75c40d..2fab6274 100644 --- a/README.md +++ b/README.md @@ -81,8 +81,8 @@ If you have actions that trigger on newly created releases, please use a generat | `failTitle` | The title of the issue created when a release fails. Set to `false` to disable opening an issue when a release fails. | `The automated release is failing 🚨` | | `labels` | The [labels](https://help.github.com/articles/about-labels) to add to the issue created when a release fails. Set to `false` to not add any label. | `['semantic-release']` | | `assignees` | The [assignees](https://help.github.com/articles/assigning-issues-and-pull-requests-to-other-github-users) to add to the issue created when a release fails. | - | -| `releasedLabels` | The [labels](https://help.github.com/articles/about-labels) to add to each issue and pull request resolved by the release. Set to `false` to not add any label. See [releasedLabels](#releasedlabels). | `['released<%= nextRelease.channel ? \` on @\${nextRelease.channel}\` : "" %>']- | -| `addReleases` | Will add release links to the GitHub Release. Can be `false`, `"bottom"` or `"top"`. See [addReleases](#addReleases). | `false` | +| `releasedLabels` | The [labels](https://help.github.com/articles/about-labels) to add to each issue and pull request resolved by the release. Set to `false` to not add any label. See [releasedLabels](#releasedlabels). | `['released<%= nextRelease.channel ? \` on @\${nextRelease.channel}\` : "" %>']- | +| `addReleases` | Will add release links to the GitHub Release. Can be `false`, `"bottom"` or `"top"`. See [addReleases](#addReleases). | `"bottom"` | #### proxy diff --git a/lib/resolve-config.js b/lib/resolve-config.js index c4635814..f2f01101 100644 --- a/lib/resolve-config.js +++ b/lib/resolve-config.js @@ -31,5 +31,5 @@ module.exports = ( : releasedLabels === false ? false : castArray(releasedLabels), - addReleases: isNil(addReleases) ? false : addReleases, + addReleases: isNil(addReleases) ? 'bottom' : addReleases, }); diff --git a/test/success.test.js b/test/success.test.js index a3744bad..c7fdfbb2 100644 --- a/test/success.test.js +++ b/test/success.test.js @@ -625,12 +625,12 @@ test.serial('Comment on issue/PR without ading a label', async (t) => { t.true(github.isDone()); }); -test.serial('Editing the release to include all release links at the bottom', async (t) => { +test.serial('Edit the release to include all the release links at the bottom by default', async (t) => { const owner = 'test_user'; const repo = 'test_repo'; const env = {GITHUB_TOKEN: 'github_token'}; const failTitle = 'The automated release is failing 🚨'; - const pluginConfig = {releasedLabels: false, addReleases: 'bottom'}; + const pluginConfig = {releasedLabels: false}; // The addReleases is omitted const prs = [{number: 1, pull_request: {}, state: 'closed'}]; const options = {repositoryUrl: `https://github.com/${owner}/${repo}.git`}; const nextRelease = {version: '2.0.0', gitTag: 'v1.0.0', name: 'v1.0.0', notes: 'Test release note body'}; @@ -682,12 +682,64 @@ test.serial('Editing the release to include all release links at the bottom', as t.true(github.isDone()); }); -test.serial('Editing the release to include all release links at the top', async (t) => { +test.serial('Edit the release to not include the release links', async (t) => { const owner = 'test_user'; const repo = 'test_repo'; const env = {GITHUB_TOKEN: 'github_token'}; const failTitle = 'The automated release is failing 🚨'; - const pluginConfig = {releasedLabels: false, addReleases: 'top'}; + const pluginConfig = {releasedLabels: false, addReleases: false}; + const prs = [{number: 1, pull_request: {}, state: 'closed'}]; + const options = {repositoryUrl: `https://github.com/${owner}/${repo}.git`}; + const nextRelease = {version: '2.0.0', gitTag: 'v1.0.0', name: 'v1.0.0', notes: 'Test release note body'}; + const lastRelease = {version: '1.0.0'}; + const commits = [{hash: '123', message: 'Commit 1 message'}]; + const releaseId = 1; + const releases = [ + {name: 'GitHub release', url: 'https://github.com/release', id: releaseId}, + {name: 'S3', url: 's3://my-bucket/release-asset'}, + {name: 'Docker: docker.io/python:slim'}, + ]; + const github = authenticate(env) + .get(`/repos/${owner}/${repo}`) + .reply(200, {full_name: `${owner}/${repo}`}) + .get( + `/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${escape('is:merged')}+${commits + .map((commit) => commit.hash) + .join('+')}` + ) + .reply(200, {items: prs}) + .get(`/repos/${owner}/${repo}/pulls/1/commits`) + .reply(200, [{sha: commits[0].hash}]) + .post(`/repos/${owner}/${repo}/issues/1/comments`, {body: /This PR is included/}) + .reply(200, {html_url: 'https://github.com/successcomment-1'}) + .get( + `/search/issues?q=${escape('in:title')}+${escape(`repo:${owner}/${repo}`)}+${escape('type:issue')}+${escape( + 'state:open' + )}+${escape(failTitle)}` + ) + .reply(200, {items: []}); + + await success(pluginConfig, { + env, + options, + branch: {name: 'master'}, + lastRelease, + commits, + nextRelease, + releases, + logger: t.context.logger, + }); + + t.true(t.context.log.calledWith('Added comment to issue #%d: %s', 1, 'https://github.com/successcomment-1')); + t.true(github.isDone()); +}); + +test.serial('Edit the release to include all the release links at the bottom', async (t) => { + const owner = 'test_user'; + const repo = 'test_repo'; + const env = {GITHUB_TOKEN: 'github_token'}; + const failTitle = 'The automated release is failing 🚨'; + const pluginConfig = {releasedLabels: false, addReleases: 'bottom'}; const prs = [{number: 1, pull_request: {}, state: 'closed'}]; const options = {repositoryUrl: `https://github.com/${owner}/${repo}.git`}; const nextRelease = {version: '2.0.0', gitTag: 'v1.0.0', name: 'v1.0.0', notes: 'Test release note body'}; @@ -720,7 +772,7 @@ test.serial('Editing the release to include all release links at the top', async ) .reply(200, {items: []}) .patch(`/repos/${owner}/${repo}/releases/${releaseId}`, { - body: getReleaseLinks(releases).concat('\n---\n', nextRelease.notes), + body: nextRelease.notes.concat('\n---\n', getReleaseLinks(releases)), }) .reply(200, {html_url: releaseUrl}); @@ -739,7 +791,7 @@ test.serial('Editing the release to include all release links at the top', async t.true(github.isDone()); }); -test.serial('Editing the release to include all release links with no additional releases (top)', async (t) => { +test.serial('Edit the release to include all the release links at the top', async (t) => { const owner = 'test_user'; const repo = 'test_repo'; const env = {GITHUB_TOKEN: 'github_token'}; @@ -750,8 +802,13 @@ test.serial('Editing the release to include all release links with no additional const nextRelease = {version: '2.0.0', gitTag: 'v1.0.0', name: 'v1.0.0', notes: 'Test release note body'}; const lastRelease = {version: '1.0.0'}; const commits = [{hash: '123', message: 'Commit 1 message'}]; + const releaseUrl = `https://github.com/${owner}/${repo}/releases/${nextRelease.version}`; const releaseId = 1; - const releases = [{name: 'GitHub release', url: 'https://github.com/release', id: releaseId}]; + const releases = [ + {name: 'GitHub release', url: 'https://github.com/release', id: releaseId}, + {name: 'S3', url: 's3://my-bucket/release-asset'}, + {name: 'Docker: docker.io/python:slim'}, + ]; const github = authenticate(env) .get(`/repos/${owner}/${repo}`) .reply(200, {full_name: `${owner}/${repo}`}) @@ -770,7 +827,11 @@ test.serial('Editing the release to include all release links with no additional 'state:open' )}+${escape(failTitle)}` ) - .reply(200, {items: []}); + .reply(200, {items: []}) + .patch(`/repos/${owner}/${repo}/releases/${releaseId}`, { + body: getReleaseLinks(releases).concat('\n---\n', nextRelease.notes), + }) + .reply(200, {html_url: releaseUrl}); await success(pluginConfig, { env, @@ -787,12 +848,12 @@ test.serial('Editing the release to include all release links with no additional t.true(github.isDone()); }); -test.serial('Editing the release to include all release links with no additional releases (bottom)', async (t) => { +test.serial('Edit the release to include all the release links at the top with no additional releases', async (t) => { const owner = 'test_user'; const repo = 'test_repo'; const env = {GITHUB_TOKEN: 'github_token'}; const failTitle = 'The automated release is failing 🚨'; - const pluginConfig = {releasedLabels: false, addReleases: 'bottom'}; + const pluginConfig = {releasedLabels: false, addReleases: 'top'}; const prs = [{number: 1, pull_request: {}, state: 'closed'}]; const options = {repositoryUrl: `https://github.com/${owner}/${repo}.git`}; const nextRelease = {version: '2.0.0', gitTag: 'v1.0.0', name: 'v1.0.0', notes: 'Test release note body'}; @@ -835,7 +896,58 @@ test.serial('Editing the release to include all release links with no additional t.true(github.isDone()); }); -test.serial('Editing the release to include all release links with no releases', async (t) => { +test.serial( + 'Edit the release to include all the release links at the bottom with no additional releases', + async (t) => { + const owner = 'test_user'; + const repo = 'test_repo'; + const env = {GITHUB_TOKEN: 'github_token'}; + const failTitle = 'The automated release is failing 🚨'; + const pluginConfig = {releasedLabels: false, addReleases: 'bottom'}; + const prs = [{number: 1, pull_request: {}, state: 'closed'}]; + const options = {repositoryUrl: `https://github.com/${owner}/${repo}.git`}; + const nextRelease = {version: '2.0.0', gitTag: 'v1.0.0', name: 'v1.0.0', notes: 'Test release note body'}; + const lastRelease = {version: '1.0.0'}; + const commits = [{hash: '123', message: 'Commit 1 message'}]; + const releaseId = 1; + const releases = [{name: 'GitHub release', url: 'https://github.com/release', id: releaseId}]; + const github = authenticate(env) + .get(`/repos/${owner}/${repo}`) + .reply(200, {full_name: `${owner}/${repo}`}) + .get( + `/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${escape('is:merged')}+${commits + .map((commit) => commit.hash) + .join('+')}` + ) + .reply(200, {items: prs}) + .get(`/repos/${owner}/${repo}/pulls/1/commits`) + .reply(200, [{sha: commits[0].hash}]) + .post(`/repos/${owner}/${repo}/issues/1/comments`, {body: /This PR is included/}) + .reply(200, {html_url: 'https://github.com/successcomment-1'}) + .get( + `/search/issues?q=${escape('in:title')}+${escape(`repo:${owner}/${repo}`)}+${escape('type:issue')}+${escape( + 'state:open' + )}+${escape(failTitle)}` + ) + .reply(200, {items: []}); + + await success(pluginConfig, { + env, + options, + branch: {name: 'master'}, + lastRelease, + commits, + nextRelease, + releases, + logger: t.context.logger, + }); + + t.true(t.context.log.calledWith('Added comment to issue #%d: %s', 1, 'https://github.com/successcomment-1')); + t.true(github.isDone()); + } +); + +test.serial('Edit the release to include all the release links with no releases', async (t) => { const owner = 'test_user'; const repo = 'test_repo'; const env = {GITHUB_TOKEN: 'github_token'}; @@ -882,7 +994,7 @@ test.serial('Editing the release to include all release links with no releases', t.true(github.isDone()); }); -test.serial('Editing the release with no ID in the release', async (t) => { +test.serial('Edit the release to include all the release links with no ID in the release', async (t) => { const owner = 'test_user'; const repo = 'test_repo'; const env = {GITHUB_TOKEN: 'github_token'};