diff --git a/.gitignore b/.gitignore index 0fd2342..71eac1a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ repository.json user.json tests/sample-test-release-v2.json tests/sample-test-release-v3.json +tests/sample-test-release-null-body.json diff --git a/index.js b/index.js index 49c5d10..7f51c4c 100644 --- a/index.js +++ b/index.js @@ -110,7 +110,7 @@ const convertLinksToMarkdown = (text) => { * @returns {string} The formatted description. */ const formatDescription = (description) => { - let edit = removeCarriageReturn(description); + let edit = removeCarriageReturn(description ?? ''); edit = removeHTMLComments(edit); edit = reduceNewlines(edit); @@ -303,8 +303,8 @@ const run = async () => { const { body, html_url, name } = getContext(); - if (!body || !name) { - return core.setFailed('No GitHub release payload found. When using workflow_dispatch, pass release_name and release_body inputs to the action.'); + if (!name) { + return core.setFailed('No GitHub release payload found. When using workflow_dispatch, pass release_name to the action.'); } const description = formatDescription(body); diff --git a/tests/manual-dispatch.test.js b/tests/manual-dispatch.test.js index 4bff355..e907a2e 100644 --- a/tests/manual-dispatch.test.js +++ b/tests/manual-dispatch.test.js @@ -34,6 +34,14 @@ const githubMock = { } }; +beforeEach(() => { + fetchMock.mockClear(); + coreMock.setFailed.mockClear(); + coreMock.info.mockClear(); + coreMock.warning.mockClear(); + githubMock.context.payload = {}; +}); + jest.unstable_mockModule('@actions/core', () => ({ default: coreMock })); @@ -72,4 +80,27 @@ describe('manual dispatch integration', () => { expect(coreMock.setFailed).not.toHaveBeenCalled(); expect(coreMock.info).toHaveBeenCalledWith('{"id":"discord-message-id"}'); }); + + test('run() tolerates a release payload with a null body', async () => { + githubMock.context.payload.release = { + name: 'v1.2.4', + body: null, + html_url: 'https://github.com/owner/repo/releases/tag/v1.2.4' + }; + + const { run } = await import('../index.js'); + + await run(); + + expect(fetchMock).toHaveBeenCalledTimes(1); + + const request = JSON.parse(fetchMock.mock.calls[0][1].body); + expect(request.embeds[0]).toMatchObject({ + title: 'v1.2.4', + url: 'https://github.com/owner/repo/releases/tag/v1.2.4', + description: '' + }); + + expect(coreMock.setFailed).not.toHaveBeenCalled(); + }); });