Skip to content

Commit

Permalink
support github's auto generated release notes (#843)
Browse files Browse the repository at this point in the history
* support github's auto generated release notes

* fixed defaults. added test

*  removed redundant default undefined value for autoGenerate

* removed redundant default undefined value in stub
  • Loading branch information
rlsf committed Dec 11, 2021
1 parent 1b1034c commit b612ce7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/plugin/github/GitHub.js
Expand Up @@ -187,12 +187,12 @@ class GitHub extends Release {

getOctokitReleaseOptions(options = {}) {
const { owner, project: repo } = this.getContext('repo');
const { releaseName, draft = false, preRelease = false } = this.options;
const { releaseName, draft = false, preRelease = false, autoGenerate } = this.options;
const { tagName } = this.config.getContext();
const { version, releaseNotes } = this.getContext();
const { isPreRelease } = parseVersion(version);
const name = format(releaseName, this.config.getContext());
const body = releaseNotes;
const body = autoGenerate ? null : releaseNotes;

return Object.assign(options, {
owner,
Expand All @@ -201,7 +201,8 @@ class GitHub extends Release {
name,
body,
draft,
prerelease: isPreRelease || preRelease
prerelease: isPreRelease || preRelease,
generate_release_notes: autoGenerate
});
}

Expand Down
27 changes: 27 additions & 0 deletions test/github.js
Expand Up @@ -99,6 +99,33 @@ test('should create a pre-release and draft release notes', async t => {
exec.restore();
});

test('should create auto generated release notes', async t => {
const options = {
git,
github: {
pushRepo,
tokenRef,
release: true,
releaseName: 'Release ${tagName}',
autoGenerate: true
}
};
const github = factory(GitHub, { options });
const exec = sinon.stub(github.shell, 'exec').callThrough();
exec.withArgs('git describe --tags --match=* --abbrev=0').resolves('2.0.1');

interceptAuthentication();
interceptCollaborator();
interceptCreate({ body: { tag_name: '2.0.2', name: 'Release 2.0.2', draft: false, prerelease: false, generate_release_notes: true } });

await runTasks(github);

const { isReleased, releaseUrl } = github.getContext();
t.true(isReleased);
t.is(releaseUrl, 'https://github.com/user/repo/releases/tag/2.0.2');
exec.restore();
});

test('should update release and upload assets', async t => {
const asset = 'file1';
const options = {
Expand Down
5 changes: 3 additions & 2 deletions test/stub/github.js
Expand Up @@ -40,10 +40,10 @@ const interceptCreate = ({
host = 'github.com',
owner = 'user',
project = 'repo',
body: { tag_name, name = '', body = null, prerelease = false, draft = false }
body: { tag_name, name = '', body = null, prerelease = false, draft = false, generate_release_notes }
} = {}) =>
nock(api)
.post(`/repos/${owner}/${project}/releases`, { tag_name, name, body, prerelease, draft })
.post(`/repos/${owner}/${project}/releases`, { tag_name, name, body, prerelease, draft, generate_release_notes })
.reply(() => {
const id = 1;
const responseBody = {
Expand All @@ -53,6 +53,7 @@ const interceptCreate = ({
body,
prerelease,
draft,
generate_release_notes,
upload_url: `https://uploads.${host}/repos/${owner}/${project}/releases/${id}/assets{?name,label}`,
html_url: `https://${host}/${owner}/${project}/releases/tag/${tag_name}`
};
Expand Down

0 comments on commit b612ce7

Please sign in to comment.