diff --git a/lib/plugin/github/GitHub.js b/lib/plugin/github/GitHub.js index 0b5513ac..6ad3306b 100644 --- a/lib/plugin/github/GitHub.js +++ b/lib/plugin/github/GitHub.js @@ -31,6 +31,12 @@ const parseErrormsg = err => { return msg; }; +const truncateBody = body => { + // https://github.com/release-it/release-it/issues/965 + if (body && body.length >= 124000) return body.substring(0, 124000) + '...'; + return body; +}; + class GitHub extends Release { constructor(...args) { super(...args); @@ -200,7 +206,7 @@ class GitHub extends Release { const { version, releaseNotes, isUpdate } = this.getContext(); const { isPreRelease } = parseVersion(version); const name = format(releaseName, this.config.getContext()); - const body = autoGenerate ? (isUpdate ? null : '') : releaseNotes; + const body = autoGenerate ? (isUpdate ? null : '') : truncateBody(releaseNotes); return Object.assign(options, { owner, diff --git a/test/github.js b/test/github.js index 9a47ffc6..ca97ca6e 100644 --- a/test/github.js +++ b/test/github.js @@ -425,3 +425,33 @@ test('should generate GitHub web release url for enterprise host', async t => { ); exec.restore(); }); + +test('should truncate long body', async t => { + const releaseNotes = 'a'.repeat(125001); + const body = 'a'.repeat(124000) + '...'; + const options = { + git, + github: { + pushRepo, + tokenRef, + release: true, + releaseName: 'Release ${tagName}', + releaseNotes: 'echo ' + releaseNotes + } + }; + const github = factory(GitHub, { options }); + const exec = sinon.stub(github.shell, 'exec').callThrough(); + exec.withArgs('git log --pretty=format:"* %s (%h)" ${from}...${to}').resolves(''); + 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', body } }); + + 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(); +});