Skip to content
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

feat: add release links on the release description by default #326

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/resolve-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ module.exports = (
: releasedLabels === false
? false
: castArray(releasedLabels),
addReleases: isNil(addReleases) ? false : addReleases,
addReleases: isNil(addReleases) ? 'bottom' : addReleases,
});
136 changes: 124 additions & 12 deletions test/success.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'};
Expand Down Expand Up @@ -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'};
Expand Down Expand Up @@ -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});

Expand All @@ -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'};
Expand All @@ -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}`})
Expand All @@ -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,
Expand All @@ -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'};
Expand Down Expand Up @@ -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'};
Expand Down Expand Up @@ -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'};
Expand Down