You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Returns first suitable line number and side for a review comment.
150606
-
// Preference order: first added line ('+' -> RIGHT), then context (' ' -> RIGHT), then deletion ('-' -> LEFT).
150607
-
if (!patch)
150608
-
return { line: 1, side: 'RIGHT' };
150609
-
const lines = patch.split('\n');
150610
-
let currentOld = 0;
150611
-
let currentNew = 0;
150612
-
// helper to parse the hunk header like: @@ -oldStart,oldCount +newStart,newCount @@
150613
-
const parseHunkHeader = (hdr) => {
150614
-
const m = hdr.match(/@@\s+-(\d+)(?:,(\d+))?\s+\+(\d+)(?:,(\d+))?\s+@@/);
150615
-
if (!m)
150616
-
return null;
150617
-
const oldStart = parseInt(m[1], 10);
150618
-
const newStart = parseInt(m[3], 10);
150619
-
return { oldStart, newStart };
150620
-
};
150621
-
// track first matches
150622
-
let firstAdded = null;
150623
-
let firstContext = null;
150624
-
let firstDeleted = null;
150625
-
for (let i = 0; i < lines.length; i++) {
150626
-
const line = lines[i];
150627
-
if (line.startsWith('@@')) {
150628
-
const parsed = parseHunkHeader(line);
150629
-
if (parsed) {
150630
-
currentOld = parsed.oldStart;
150631
-
currentNew = parsed.newStart;
150632
-
}
150633
-
continue;
150634
-
}
150635
-
if (line.startsWith('+')) {
150636
-
// addition: belongs to new file
150637
-
if (firstAdded === null)
150638
-
firstAdded = currentNew;
150639
-
currentNew++;
150640
-
continue;
150641
-
}
150642
-
if (line.startsWith('-')) {
150643
-
// deletion: belongs to old file
150644
-
if (firstDeleted === null)
150645
-
firstDeleted = currentOld;
150646
-
currentOld++;
150647
-
continue;
150648
-
}
150649
-
// context line (starts with space or other)
150650
-
if (line.startsWith(' ') || line.length === 0) {
150651
-
if (firstContext === null)
150652
-
firstContext = currentNew;
150653
-
currentOld++;
150654
-
currentNew++;
150655
-
continue;
150656
-
}
150657
-
}
150658
-
if (firstAdded !== null)
150659
-
return { line: firstAdded, side: 'RIGHT' };
150660
-
if (firstContext !== null)
150661
-
return { line: firstContext, side: 'RIGHT' };
150662
-
if (firstDeleted !== null)
150663
-
return { line: firstDeleted, side: 'LEFT' };
150664
-
return { line: 1, side: 'RIGHT' };
150665
-
};
150666
-
const splitPatchIntoHunks = (patch) => {
150667
-
// Split patch into individual hunks by @@ markers
150668
-
const hunks = [];
150669
-
const lines = patch.split('\n');
150670
-
let currentHunk = [];
150671
-
let currentHeader = '';
150672
-
let currentNewStart = 0;
150673
-
const parseHunkHeader = (hdr) => {
150674
-
const m = hdr.match(/@@\s+-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@/);
150675
-
if (!m)
150676
-
return 0;
150677
-
return parseInt(m[1], 10);
150678
-
};
150679
-
for (const line of lines) {
150680
-
if (line.startsWith('@@')) {
150681
-
// Save previous hunk if it exists
150682
-
if (currentHunk.length > 0) {
150683
-
hunks.push({
150684
-
header: currentHeader,
150685
-
newStart: currentNewStart,
150686
-
content: currentHunk.join('\n'),
150687
-
});
150688
-
}
150689
-
currentHeader = line;
150690
-
currentNewStart = parseHunkHeader(line);
150691
-
currentHunk = [line];
150692
-
}
150693
-
else if (currentHunk.length > 0) {
150694
-
currentHunk.push(line);
150695
-
}
150696
-
}
150697
-
// Save the last hunk
150698
-
if (currentHunk.length > 0) {
150699
-
hunks.push({
150700
-
header: currentHeader,
150701
-
newStart: currentNewStart,
150702
-
content: currentHunk.join('\n'),
150703
-
});
150704
-
}
150705
-
return hunks;
150706
-
};
150707
150612
150708
150613
150709
150614
/***/ }),
@@ -150747,10 +150652,16 @@ class Chat {
150747
150652
const userPrompt = process.env.PROMPT || 'Please review the following code patch. Focus on potential bugs, risks, and improvement suggestions.';
150748
150653
const jsonFormatRequirement = '\nProvide your feedback in a strict JSON format with the following structure:\n' +
150749
150654
'{\n' +
150750
-
' "lgtm": boolean, // true if the code looks good to merge, false if there are concerns\n' +
150751
-
' "review_comment": string // Your detailed review comments. You can use markdown syntax in this string, but the overall response must be a valid JSON\n' +
0 commit comments