Skip to content

Commit 1325562

Browse files
Copilotalexr00
andcommitted
Address code review feedback
- Extract regex pattern to named constant PRESERVE_LINE_PATTERN - Replace deprecated substr() with slice() - Improve regex to match only spaces/tabs explicitly instead of \s - Add detailed comments explaining the pattern Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 21ff4a3 commit 1325562

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/github/folderRepositoryManager.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,6 +2891,12 @@ function unwrapCommitMessageBody(body: string): string {
28912891
return body;
28922892
}
28932893

2894+
// Pattern to detect lines that should be preserved (not joined):
2895+
// - Lines starting with whitespace (indented/code blocks)
2896+
// - Lines starting with list markers (*, -, +, >)
2897+
// - Lines starting with numbered list items (e.g., "1. ")
2898+
const PRESERVE_LINE_PATTERN = /^[ \t*\-+>]|^\d+\./;
2899+
28942900
const lines = body.split('\n');
28952901
const result: string[] = [];
28962902
let i = 0;
@@ -2907,7 +2913,7 @@ function unwrapCommitMessageBody(body: string): string {
29072913

29082914
// Check if this line should NOT be joined with the next
29092915
// Lines that start with special formatting characters should be preserved
2910-
const shouldPreserveLine = /^[\s*\-+>]|^\d+\./.test(line);
2916+
const shouldPreserveLine = PRESERVE_LINE_PATTERN.test(line);
29112917

29122918
if (shouldPreserveLine) {
29132919
result.push(line);
@@ -2929,7 +2935,7 @@ function unwrapCommitMessageBody(body: string): string {
29292935
}
29302936

29312937
// Stop at lines that start with special formatting
2932-
if (/^[\s*\-+>]|^\d+\./.test(nextLine)) {
2938+
if (PRESERVE_LINE_PATTERN.test(nextLine)) {
29332939
break;
29342940
}
29352941

@@ -2952,7 +2958,7 @@ export const titleAndBodyFrom = async (promise: Promise<string | undefined>): Pr
29522958
const idxLineBreak = message.indexOf('\n');
29532959
const rawBody = idxLineBreak === -1 ? '' : message.slice(idxLineBreak + 1).trim();
29542960
return {
2955-
title: idxLineBreak === -1 ? message : message.substr(0, idxLineBreak),
2961+
title: idxLineBreak === -1 ? message : message.slice(0, idxLineBreak),
29562962

29572963
body: unwrapCommitMessageBody(rawBody),
29582964
};

0 commit comments

Comments
 (0)