Skip to content

Commit be74a0c

Browse files
authored
fix(create-batched-commit-message): handle multiline commit messages (#732)
1 parent 419ece4 commit be74a0c

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

dist/813.index.js

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/813.index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/helpers/create-batched-commit-message.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ export const createBatchedCommitMessage = () => {
2727
return eventPayload.commits
2828
.map(commit => {
2929
const prNumberWithParens = commit.message.match(/\(#(\d+)\)/)?.[0] ?? '';
30-
const messageWithoutPrNumber = commit.message.replace(prNumberWithParens, '').trim();
30+
const messageWithoutPrNumber = commit.message.replace(prNumberWithParens, '').split('\n')[0]?.trim() ?? '';
3131
const truncatedMessage = messageWithoutPrNumber.slice(0, maxCharactersPerMessage);
32-
if (truncatedMessage.length < messageWithoutPrNumber.length) {
33-
return `${truncatedMessage}... ${prNumberWithParens ?? 'PR unknown'}`;
34-
}
35-
return commit.message;
32+
const ellipses = truncatedMessage.length < messageWithoutPrNumber.length ? '...' : '';
33+
return `${truncatedMessage}${ellipses} ${prNumberWithParens}`;
3634
})
3735
.join(' and ');
3836
};

test/helpers/create-batched-commit-message.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('createBatchedCommitMessage', () => {
4040
});
4141
});
4242

43-
describe('createBatchedCommitMessage', () => {
43+
describe('createBatchedCommitMessage long messages', () => {
4444
beforeEach(() => {
4545
context.payload.commits = [
4646
{
@@ -62,3 +62,24 @@ describe('createBatchedCommitMessage', () => {
6262
);
6363
});
6464
});
65+
66+
describe('createBatchedCommitMessage multiline messages', () => {
67+
beforeEach(() => {
68+
context.payload.commits = [
69+
{
70+
id: '1234567890abcdef',
71+
message: 'Fix a really really long issue \n' + ' \n' + ' * fix the issue\n' + ' \n' + ' * definitely fix the issue (#1)',
72+
author: { name: 'John Doe', email: '' }
73+
},
74+
{
75+
id: '1234567891abcdef',
76+
message: 'Fix another really really long issue \n' + ' \n' + ' * fix the issue\n' + ' \n' + ' * definitely fix the issue (#2)',
77+
author: { name: 'Jane Doe', email: '' }
78+
}
79+
];
80+
});
81+
it('should truncate the message', () => {
82+
const result = createBatchedCommitMessage();
83+
expect(result).toBe('Fix a really really long issue (#1) and Fix another really really long issue (#2)');
84+
});
85+
});

0 commit comments

Comments
 (0)