diff --git a/dist/813.index.js b/dist/813.index.js index ccfafd7e..851e765b 100644 --- a/dist/813.index.js +++ b/dist/813.index.js @@ -37,12 +37,10 @@ const createBatchedCommitMessage = () => { return eventPayload.commits .map(commit => { const prNumberWithParens = commit.message.match(/\(#(\d+)\)/)?.[0] ?? ''; - const messageWithoutPrNumber = commit.message.replace(prNumberWithParens, '').trim(); + const messageWithoutPrNumber = commit.message.replace(prNumberWithParens, '').split('\n')[0]?.trim() ?? ''; const truncatedMessage = messageWithoutPrNumber.slice(0, maxCharactersPerMessage); - if (truncatedMessage.length < messageWithoutPrNumber.length) { - return `${truncatedMessage}... ${prNumberWithParens ?? 'PR unknown'}`; - } - return commit.message; + const ellipses = truncatedMessage.length < messageWithoutPrNumber.length ? '...' : ''; + return `${truncatedMessage}${ellipses} ${prNumberWithParens}`; }) .join(' and '); }; diff --git a/dist/813.index.js.map b/dist/813.index.js.map index 090f1152..70d75354 100644 --- a/dist/813.index.js.map +++ b/dist/813.index.js.map @@ -1 +1 @@ -{"version":3,"file":"813.index.js","mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sources":[".././src/helpers/create-batched-commit-message.ts"],"sourcesContent":["/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { context } from '@actions/github';\nimport { error } from '@actions/core';\nimport { PushEvent } from '@octokit/webhooks-types';\n\nexport const createBatchedCommitMessage = () => {\n const eventPayload = context.payload as PushEvent;\n if (!('commits' in eventPayload)) {\n error('No commits found in the event payload.');\n return;\n }\n\n const maxCharactersPerMessage = 50;\n\n return eventPayload.commits\n .map(commit => {\n const prNumberWithParens = commit.message.match(/\\(#(\\d+)\\)/)?.[0] ?? '';\n const messageWithoutPrNumber = commit.message.replace(prNumberWithParens, '').trim();\n const truncatedMessage = messageWithoutPrNumber.slice(0, maxCharactersPerMessage);\n if (truncatedMessage.length < messageWithoutPrNumber.length) {\n return `${truncatedMessage}... ${prNumberWithParens ?? 'PR unknown'}`;\n }\n return commit.message;\n })\n .join(' and ');\n};\n"],"names":[],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"813.index.js","mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sources":[".././src/helpers/create-batched-commit-message.ts"],"sourcesContent":["/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { context } from '@actions/github';\nimport { error } from '@actions/core';\nimport { PushEvent } from '@octokit/webhooks-types';\n\nexport const createBatchedCommitMessage = () => {\n const eventPayload = context.payload as PushEvent;\n if (!('commits' in eventPayload)) {\n error('No commits found in the event payload.');\n return;\n }\n\n const maxCharactersPerMessage = 50;\n\n return eventPayload.commits\n .map(commit => {\n const prNumberWithParens = commit.message.match(/\\(#(\\d+)\\)/)?.[0] ?? '';\n const messageWithoutPrNumber = commit.message.replace(prNumberWithParens, '').split('\\n')[0]?.trim() ?? '';\n const truncatedMessage = messageWithoutPrNumber.slice(0, maxCharactersPerMessage);\n const ellipses = truncatedMessage.length < messageWithoutPrNumber.length ? '...' : '';\n return `${truncatedMessage}${ellipses} ${prNumberWithParens}`;\n })\n .join(' and ');\n};\n"],"names":[],"sourceRoot":""} \ No newline at end of file diff --git a/src/helpers/create-batched-commit-message.ts b/src/helpers/create-batched-commit-message.ts index 310e80aa..ded11caa 100644 --- a/src/helpers/create-batched-commit-message.ts +++ b/src/helpers/create-batched-commit-message.ts @@ -27,12 +27,10 @@ export const createBatchedCommitMessage = () => { return eventPayload.commits .map(commit => { const prNumberWithParens = commit.message.match(/\(#(\d+)\)/)?.[0] ?? ''; - const messageWithoutPrNumber = commit.message.replace(prNumberWithParens, '').trim(); + const messageWithoutPrNumber = commit.message.replace(prNumberWithParens, '').split('\n')[0]?.trim() ?? ''; const truncatedMessage = messageWithoutPrNumber.slice(0, maxCharactersPerMessage); - if (truncatedMessage.length < messageWithoutPrNumber.length) { - return `${truncatedMessage}... ${prNumberWithParens ?? 'PR unknown'}`; - } - return commit.message; + const ellipses = truncatedMessage.length < messageWithoutPrNumber.length ? '...' : ''; + return `${truncatedMessage}${ellipses} ${prNumberWithParens}`; }) .join(' and '); }; diff --git a/test/helpers/create-batched-commit-message.test.ts b/test/helpers/create-batched-commit-message.test.ts index df24c948..a25e7596 100644 --- a/test/helpers/create-batched-commit-message.test.ts +++ b/test/helpers/create-batched-commit-message.test.ts @@ -40,7 +40,7 @@ describe('createBatchedCommitMessage', () => { }); }); -describe('createBatchedCommitMessage', () => { +describe('createBatchedCommitMessage long messages', () => { beforeEach(() => { context.payload.commits = [ { @@ -62,3 +62,24 @@ describe('createBatchedCommitMessage', () => { ); }); }); + +describe('createBatchedCommitMessage multiline messages', () => { + beforeEach(() => { + context.payload.commits = [ + { + id: '1234567890abcdef', + message: 'Fix a really really long issue \n' + ' \n' + ' * fix the issue\n' + ' \n' + ' * definitely fix the issue (#1)', + author: { name: 'John Doe', email: '' } + }, + { + id: '1234567891abcdef', + message: 'Fix another really really long issue \n' + ' \n' + ' * fix the issue\n' + ' \n' + ' * definitely fix the issue (#2)', + author: { name: 'Jane Doe', email: '' } + } + ]; + }); + it('should truncate the message', () => { + const result = createBatchedCommitMessage(); + expect(result).toBe('Fix a really really long issue (#1) and Fix another really really long issue (#2)'); + }); +});