Skip to content

Commit

Permalink
Truncate github release notes body > 124k characters (closes #965)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Mar 9, 2023
1 parent eaf85d7 commit 218ffc1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/plugin/github/GitHub.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions test/github.js
Expand Up @@ -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();
});

0 comments on commit 218ffc1

Please sign in to comment.