From a5f38d0072dea96a2960f32fd6365ae86ca88247 Mon Sep 17 00:00:00 2001 From: Harjot Gill Date: Tue, 1 Aug 2023 11:20:06 -0700 Subject: [PATCH 01/11] update prompt --- dist/index.js | 34 +++++++++++++++++++++++----------- src/prompts.ts | 12 ++++++------ src/review.ts | 21 ++++++++++++++++----- 3 files changed, 45 insertions(+), 22 deletions(-) diff --git a/dist/index.js b/dist/index.js index 7aca938a..a0e2b9b0 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6881,18 +6881,18 @@ format \`\`. ---new_hunk--- \`\`\` - 12: z = x / y - 13: return z - 14: + z = x / y + return z + 15: def add(x, y): 16: z = x - y 17: retrn z 18: 19: def multiply(x, y): 20: return x * y - 21: - 22: def subtract(x, y): - 23: z = x - y + + def subtract(x, y): + z = x - y \`\`\` ---old_hunk--- @@ -7921,26 +7921,38 @@ const parsePatch = (patch) => { } const oldHunkLines = []; const newHunkLines = []; - // let old_line = hunkInfo.old_hunk.start_line let newLine = hunkInfo.newHunk.startLine; const lines = patch.split('\n').slice(1); // Skip the @@ line // Remove the last line if it's empty if (lines[lines.length - 1] === '') { lines.pop(); } + // Keep track of first 3 and last 3 lines in the new hunk + const startLines = 3; + const endLines = lines.length - 3; for (const line of lines) { if (line.startsWith('-')) { oldHunkLines.push(`${line.substring(1)}`); - // old_line++ } else if (line.startsWith('+')) { - newHunkLines.push(`${newLine}: ${line.substring(1)}`); + // Skip line number annotations for the first 3 and the last 3 lines + if (newHunkLines.length < startLines || newHunkLines.length >= endLines) { + newHunkLines.push(`${line.substring(1)}`); + } + else { + newHunkLines.push(`${newLine}: ${line.substring(1)}`); + } newLine++; } else { oldHunkLines.push(`${line}`); - newHunkLines.push(`${newLine}: ${line}`); - // old_line++ + // Skip line number annotations for the first 3 and the last 3 lines + if (newHunkLines.length < startLines || newHunkLines.length >= endLines) { + newHunkLines.push(`${line}`); + } + else { + newHunkLines.push(`${newLine}: ${line}`); + } newLine++; } } diff --git a/src/prompts.ts b/src/prompts.ts index 69e54f25..dc8fa29b 100644 --- a/src/prompts.ts +++ b/src/prompts.ts @@ -207,18 +207,18 @@ format \`\`. ---new_hunk--- \`\`\` - 12: z = x / y - 13: return z - 14: + z = x / y + return z + 15: def add(x, y): 16: z = x - y 17: retrn z 18: 19: def multiply(x, y): 20: return x * y - 21: - 22: def subtract(x, y): - 23: z = x - y + + def subtract(x, y): + z = x - y \`\`\` ---old_hunk--- diff --git a/src/review.ts b/src/review.ts index e74f8322..8fb19bb7 100644 --- a/src/review.ts +++ b/src/review.ts @@ -810,7 +810,6 @@ const parsePatch = ( const oldHunkLines: string[] = [] const newHunkLines: string[] = [] - // let old_line = hunkInfo.old_hunk.start_line let newLine = hunkInfo.newHunk.startLine const lines = patch.split('\n').slice(1) // Skip the @@ line @@ -820,17 +819,29 @@ const parsePatch = ( lines.pop() } + // Keep track of first 3 and last 3 lines in the new hunk + const startLines = 3 + const endLines = lines.length - 3 + for (const line of lines) { if (line.startsWith('-')) { oldHunkLines.push(`${line.substring(1)}`) - // old_line++ } else if (line.startsWith('+')) { - newHunkLines.push(`${newLine}: ${line.substring(1)}`) + // Skip line number annotations for the first 3 and the last 3 lines + if (newHunkLines.length < startLines || newHunkLines.length >= endLines) { + newHunkLines.push(`${line.substring(1)}`) + } else { + newHunkLines.push(`${newLine}: ${line.substring(1)}`) + } newLine++ } else { oldHunkLines.push(`${line}`) - newHunkLines.push(`${newLine}: ${line}`) - // old_line++ + // Skip line number annotations for the first 3 and the last 3 lines + if (newHunkLines.length < startLines || newHunkLines.length >= endLines) { + newHunkLines.push(`${line}`) + } else { + newHunkLines.push(`${newLine}: ${line}`) + } newLine++ } } From bcb17de000056b3e175765007b5f085cd22f736a Mon Sep 17 00:00:00 2001 From: Harjot Gill Date: Tue, 1 Aug 2023 11:36:51 -0700 Subject: [PATCH 02/11] update prompt --- dist/index.js | 18 +++++++++++------- src/review.ts | 20 +++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/dist/index.js b/dist/index.js index a0e2b9b0..0740d226 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7677,6 +7677,10 @@ ${lib_commenter/* SHORT_SUMMARY_END_TAG */.Zb} ### Ignoring further reviews - Type \`@coderabbitai: ignore\` anywhere in the PR description to ignore further reviews from the bot. +### Support us :) + +If you like this project, please support is by purchasing the [Pro version](https://coderabbit.ai)! The Pro version has advanced context and several proprietary improvements compared to the open source version. + `; statusMsg += ` @@ -7927,16 +7931,17 @@ const parsePatch = (patch) => { if (lines[lines.length - 1] === '') { lines.pop(); } - // Keep track of first 3 and last 3 lines in the new hunk - const startLines = 3; - const endLines = lines.length - 3; + // Skip annotations for the first 3 and last 3 lines + const skipStart = 3; + const skipEnd = 3; + let currentLine = 0; for (const line of lines) { + currentLine++; if (line.startsWith('-')) { oldHunkLines.push(`${line.substring(1)}`); } else if (line.startsWith('+')) { - // Skip line number annotations for the first 3 and the last 3 lines - if (newHunkLines.length < startLines || newHunkLines.length >= endLines) { + if (currentLine <= skipStart || currentLine > lines.length - skipEnd) { newHunkLines.push(`${line.substring(1)}`); } else { @@ -7946,8 +7951,7 @@ const parsePatch = (patch) => { } else { oldHunkLines.push(`${line}`); - // Skip line number annotations for the first 3 and the last 3 lines - if (newHunkLines.length < startLines || newHunkLines.length >= endLines) { + if (currentLine <= skipStart || currentLine > lines.length - skipEnd) { newHunkLines.push(`${line}`); } else { diff --git a/src/review.ts b/src/review.ts index 8fb19bb7..5f0f43fc 100644 --- a/src/review.ts +++ b/src/review.ts @@ -478,6 +478,10 @@ ${SHORT_SUMMARY_END_TAG} ### Ignoring further reviews - Type \`@coderabbitai: ignore\` anywhere in the PR description to ignore further reviews from the bot. +### Support us :) + +If you like this project, please support is by purchasing the [Pro version](https://coderabbit.ai)! The Pro version has advanced context and several proprietary improvements compared to the open source version. + ` @@ -819,16 +823,19 @@ const parsePatch = ( lines.pop() } - // Keep track of first 3 and last 3 lines in the new hunk - const startLines = 3 - const endLines = lines.length - 3 + // Skip annotations for the first 3 and last 3 lines + const skipStart = 3 + const skipEnd = 3 + + let currentLine = 0 for (const line of lines) { + currentLine++ + if (line.startsWith('-')) { oldHunkLines.push(`${line.substring(1)}`) } else if (line.startsWith('+')) { - // Skip line number annotations for the first 3 and the last 3 lines - if (newHunkLines.length < startLines || newHunkLines.length >= endLines) { + if (currentLine <= skipStart || currentLine > lines.length - skipEnd) { newHunkLines.push(`${line.substring(1)}`) } else { newHunkLines.push(`${newLine}: ${line.substring(1)}`) @@ -836,8 +843,7 @@ const parsePatch = ( newLine++ } else { oldHunkLines.push(`${line}`) - // Skip line number annotations for the first 3 and the last 3 lines - if (newHunkLines.length < startLines || newHunkLines.length >= endLines) { + if (currentLine <= skipStart || currentLine > lines.length - skipEnd) { newHunkLines.push(`${line}`) } else { newHunkLines.push(`${newLine}: ${line}`) From 97ba9090d660eb39f1f74390e7281181b653829a Mon Sep 17 00:00:00 2001 From: Harjot Gill Date: Tue, 1 Aug 2023 11:51:43 -0700 Subject: [PATCH 03/11] update prompt --- dist/index.js | 16 ++++++++-------- src/prompts.ts | 14 +++++++------- src/review.ts | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/dist/index.js b/dist/index.js index 0740d226..580c9300 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6844,13 +6844,13 @@ format \`\`. hunks. Multiple new code snippets are allowed within a single review section. - If needed, provide replacement code suggestions to fix the issues by using fenced code blocks with the \`suggestion\` as the language identifier. The - line number range must map exactly to the range (inclusive) that needs to - be replaced within a new hunk. For instance, if 2 lines of code in a hunk - need to be replaced with 15 lines of code, the line number range must be - those exact 2 lines. If an entire hunk need to be replaced with new code, - then the line number range must be the entire hunk and the new code must - exactly replace ALL the lines in the hunk. Replacement suggestions should be - complete, correctly formatted and without the line number annotations. + and must map exactly to the subset range + of lines (inclusive) that needs to be replaced within a new hunk. For instance, + if 2 lines of code in a hunk need to be replaced with 15 lines of code, the + line number range must be those exact 2 lines. All the lines between + and must be completely replaced by the + suggestion. Replacement suggestions should be complete, correctly + formatted/indented and without the line number annotations. - If there are no issues found on a line range, you MUST respond with the text \`LGTM!\` for that line range in the review section. - Reflect on your comments and line number ranges before sending the final @@ -7679,7 +7679,7 @@ ${lib_commenter/* SHORT_SUMMARY_END_TAG */.Zb} ### Support us :) -If you like this project, please support is by purchasing the [Pro version](https://coderabbit.ai)! The Pro version has advanced context and several proprietary improvements compared to the open source version. +If you like this project, please support us by purchasing the [Pro version](https://coderabbit.ai)! The Pro version has advanced context and several proprietary improvements compared to the open source version. `; diff --git a/src/prompts.ts b/src/prompts.ts index dc8fa29b..f95f5d48 100644 --- a/src/prompts.ts +++ b/src/prompts.ts @@ -170,13 +170,13 @@ format \`\`. hunks. Multiple new code snippets are allowed within a single review section. - If needed, provide replacement code suggestions to fix the issues by using fenced code blocks with the \`suggestion\` as the language identifier. The - line number range must map exactly to the range (inclusive) that needs to - be replaced within a new hunk. For instance, if 2 lines of code in a hunk - need to be replaced with 15 lines of code, the line number range must be - those exact 2 lines. If an entire hunk need to be replaced with new code, - then the line number range must be the entire hunk and the new code must - exactly replace ALL the lines in the hunk. Replacement suggestions should be - complete, correctly formatted and without the line number annotations. + and must map exactly to the subset range + of lines (inclusive) that needs to be replaced within a new hunk. For instance, + if 2 lines of code in a hunk need to be replaced with 15 lines of code, the + line number range must be those exact 2 lines. All the lines between + and must be completely replaced by the + suggestion. Replacement suggestions should be complete, correctly + formatted/indented and without the line number annotations. - If there are no issues found on a line range, you MUST respond with the text \`LGTM!\` for that line range in the review section. - Reflect on your comments and line number ranges before sending the final diff --git a/src/review.ts b/src/review.ts index 5f0f43fc..6eb85669 100644 --- a/src/review.ts +++ b/src/review.ts @@ -480,7 +480,7 @@ ${SHORT_SUMMARY_END_TAG} ### Support us :) -If you like this project, please support is by purchasing the [Pro version](https://coderabbit.ai)! The Pro version has advanced context and several proprietary improvements compared to the open source version. +If you like this project, please support us by purchasing the [Pro version](https://coderabbit.ai)! The Pro version has advanced context and several proprietary improvements compared to the open source version. ` From c6e5f1935f42ab321fcf185114c3586e4396a7a6 Mon Sep 17 00:00:00 2001 From: Harjot Gill Date: Tue, 1 Aug 2023 11:55:15 -0700 Subject: [PATCH 04/11] test --- mobile.go | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 mobile.go diff --git a/mobile.go b/mobile.go new file mode 100644 index 00000000..befc75a8 --- /dev/null +++ b/mobile.go @@ -0,0 +1,91 @@ +package main + +import ( + "fmt" + "time" +) + +// Mobile struct represents a mobile device. +type Mobile struct { + Brand string + Model string + IsOn bool + Battery int + LastUsage time.Time +} + +// TurnOn turns on the mobile device. +func (m *Mobile) TurnOn() { + m.IsOn = true + m.LastUsage = time.Now() + fmt.Printf("%s %s is now turned on.\n", m.Brand, m.Model) +} + +// TurnOff turns off the mobile device. +func (m *Mobile) TurnOff() { + m.IsOn = false + fmt.Printf("%s %s is now turned off.\n", m.Brand, m.Model) +} + +// UseMobile simulates the usage of the mobile device. +func (m *Mobile) UseMobile(minutes int) { + if !m.IsOn { + fmt.Println("Please turn on the mobile device first.") + return + } + + if m.Battery <= 0 { + fmt.Println("The mobile device is out of battery. Please charge it.") + return + } + + m.LastUsage = time.Now() + fmt.Printf("Using %s %s for %d minutes.\n", m.Brand, m.Model, minutes) + + // Simulate battery drain + m.Battery -= minutes + if m.Battery < 0 { + m.Battery = 0 + } + + // Check battery level + if m.Battery == 0 { + m.TurnOff() + fmt.Println("The mobile device is out of battery. Please charge it.") + } +} + +// ChargeMobile charges the mobile device. +func (m *Mobile) ChargeMobile(minutes int) { + m.LastUsage = time.Now() + m.Battery += minutes + if m.Battery > 100 { + m.Battery = 100 + } + fmt.Printf("Charging %s %s for %d minutes.\n", m.Brand, m.Model, minutes) +} + +func main() { + // Create a new mobile device + myMobile := Mobile{ + Brand: "Apple", + Model: "iPhone X", + IsOn: false, + Battery: 50, + } + + // Turn on the mobile device + myMobile.TurnOn() + + // Simulate using the mobile device + myMobile.UseMobile(60) + + // Charge the mobile device + myMobile.ChargeMobile(30) + + // Simulate using the mobile device again + myMobile.UseMobile(120) + + // Turn off the mobile device + myMobile.TurnOff() +} From 7bb0616e4caf2fe15c96488aee757d4e9c7a50de Mon Sep 17 00:00:00 2001 From: Harjot Gill Date: Tue, 1 Aug 2023 11:59:17 -0700 Subject: [PATCH 05/11] test --- mobile.go | 91 ------------------------------------------------------- 1 file changed, 91 deletions(-) delete mode 100644 mobile.go diff --git a/mobile.go b/mobile.go deleted file mode 100644 index befc75a8..00000000 --- a/mobile.go +++ /dev/null @@ -1,91 +0,0 @@ -package main - -import ( - "fmt" - "time" -) - -// Mobile struct represents a mobile device. -type Mobile struct { - Brand string - Model string - IsOn bool - Battery int - LastUsage time.Time -} - -// TurnOn turns on the mobile device. -func (m *Mobile) TurnOn() { - m.IsOn = true - m.LastUsage = time.Now() - fmt.Printf("%s %s is now turned on.\n", m.Brand, m.Model) -} - -// TurnOff turns off the mobile device. -func (m *Mobile) TurnOff() { - m.IsOn = false - fmt.Printf("%s %s is now turned off.\n", m.Brand, m.Model) -} - -// UseMobile simulates the usage of the mobile device. -func (m *Mobile) UseMobile(minutes int) { - if !m.IsOn { - fmt.Println("Please turn on the mobile device first.") - return - } - - if m.Battery <= 0 { - fmt.Println("The mobile device is out of battery. Please charge it.") - return - } - - m.LastUsage = time.Now() - fmt.Printf("Using %s %s for %d minutes.\n", m.Brand, m.Model, minutes) - - // Simulate battery drain - m.Battery -= minutes - if m.Battery < 0 { - m.Battery = 0 - } - - // Check battery level - if m.Battery == 0 { - m.TurnOff() - fmt.Println("The mobile device is out of battery. Please charge it.") - } -} - -// ChargeMobile charges the mobile device. -func (m *Mobile) ChargeMobile(minutes int) { - m.LastUsage = time.Now() - m.Battery += minutes - if m.Battery > 100 { - m.Battery = 100 - } - fmt.Printf("Charging %s %s for %d minutes.\n", m.Brand, m.Model, minutes) -} - -func main() { - // Create a new mobile device - myMobile := Mobile{ - Brand: "Apple", - Model: "iPhone X", - IsOn: false, - Battery: 50, - } - - // Turn on the mobile device - myMobile.TurnOn() - - // Simulate using the mobile device - myMobile.UseMobile(60) - - // Charge the mobile device - myMobile.ChargeMobile(30) - - // Simulate using the mobile device again - myMobile.UseMobile(120) - - // Turn off the mobile device - myMobile.TurnOff() -} From 9de0f5f0064528d6d7944788665e89ef5c30f3e0 Mon Sep 17 00:00:00 2001 From: Harjot Gill Date: Tue, 1 Aug 2023 12:06:58 -0700 Subject: [PATCH 06/11] test --- dist/index.js | 8 ++--- mobile.go | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/review.ts | 7 ++-- 3 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 mobile.go diff --git a/dist/index.js b/dist/index.js index 580c9300..9c72d149 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7941,15 +7941,11 @@ const parsePatch = (patch) => { oldHunkLines.push(`${line.substring(1)}`); } else if (line.startsWith('+')) { - if (currentLine <= skipStart || currentLine > lines.length - skipEnd) { - newHunkLines.push(`${line.substring(1)}`); - } - else { - newHunkLines.push(`${newLine}: ${line.substring(1)}`); - } + newHunkLines.push(`${newLine}: ${line.substring(1)}`); newLine++; } else { + // context line oldHunkLines.push(`${line}`); if (currentLine <= skipStart || currentLine > lines.length - skipEnd) { newHunkLines.push(`${line}`); diff --git a/mobile.go b/mobile.go new file mode 100644 index 00000000..befc75a8 --- /dev/null +++ b/mobile.go @@ -0,0 +1,91 @@ +package main + +import ( + "fmt" + "time" +) + +// Mobile struct represents a mobile device. +type Mobile struct { + Brand string + Model string + IsOn bool + Battery int + LastUsage time.Time +} + +// TurnOn turns on the mobile device. +func (m *Mobile) TurnOn() { + m.IsOn = true + m.LastUsage = time.Now() + fmt.Printf("%s %s is now turned on.\n", m.Brand, m.Model) +} + +// TurnOff turns off the mobile device. +func (m *Mobile) TurnOff() { + m.IsOn = false + fmt.Printf("%s %s is now turned off.\n", m.Brand, m.Model) +} + +// UseMobile simulates the usage of the mobile device. +func (m *Mobile) UseMobile(minutes int) { + if !m.IsOn { + fmt.Println("Please turn on the mobile device first.") + return + } + + if m.Battery <= 0 { + fmt.Println("The mobile device is out of battery. Please charge it.") + return + } + + m.LastUsage = time.Now() + fmt.Printf("Using %s %s for %d minutes.\n", m.Brand, m.Model, minutes) + + // Simulate battery drain + m.Battery -= minutes + if m.Battery < 0 { + m.Battery = 0 + } + + // Check battery level + if m.Battery == 0 { + m.TurnOff() + fmt.Println("The mobile device is out of battery. Please charge it.") + } +} + +// ChargeMobile charges the mobile device. +func (m *Mobile) ChargeMobile(minutes int) { + m.LastUsage = time.Now() + m.Battery += minutes + if m.Battery > 100 { + m.Battery = 100 + } + fmt.Printf("Charging %s %s for %d minutes.\n", m.Brand, m.Model, minutes) +} + +func main() { + // Create a new mobile device + myMobile := Mobile{ + Brand: "Apple", + Model: "iPhone X", + IsOn: false, + Battery: 50, + } + + // Turn on the mobile device + myMobile.TurnOn() + + // Simulate using the mobile device + myMobile.UseMobile(60) + + // Charge the mobile device + myMobile.ChargeMobile(30) + + // Simulate using the mobile device again + myMobile.UseMobile(120) + + // Turn off the mobile device + myMobile.TurnOff() +} diff --git a/src/review.ts b/src/review.ts index 6eb85669..5376c049 100644 --- a/src/review.ts +++ b/src/review.ts @@ -835,13 +835,10 @@ const parsePatch = ( if (line.startsWith('-')) { oldHunkLines.push(`${line.substring(1)}`) } else if (line.startsWith('+')) { - if (currentLine <= skipStart || currentLine > lines.length - skipEnd) { - newHunkLines.push(`${line.substring(1)}`) - } else { - newHunkLines.push(`${newLine}: ${line.substring(1)}`) - } + newHunkLines.push(`${newLine}: ${line.substring(1)}`) newLine++ } else { + // context line oldHunkLines.push(`${line}`) if (currentLine <= skipStart || currentLine > lines.length - skipEnd) { newHunkLines.push(`${line}`) From ca402a8c6d24fbaa60ecbf758b222e26414eab1a Mon Sep 17 00:00:00 2001 From: Harjot Gill Date: Tue, 1 Aug 2023 12:12:17 -0700 Subject: [PATCH 07/11] test --- mobile.go | 91 ------------------------------------------------------- 1 file changed, 91 deletions(-) delete mode 100644 mobile.go diff --git a/mobile.go b/mobile.go deleted file mode 100644 index befc75a8..00000000 --- a/mobile.go +++ /dev/null @@ -1,91 +0,0 @@ -package main - -import ( - "fmt" - "time" -) - -// Mobile struct represents a mobile device. -type Mobile struct { - Brand string - Model string - IsOn bool - Battery int - LastUsage time.Time -} - -// TurnOn turns on the mobile device. -func (m *Mobile) TurnOn() { - m.IsOn = true - m.LastUsage = time.Now() - fmt.Printf("%s %s is now turned on.\n", m.Brand, m.Model) -} - -// TurnOff turns off the mobile device. -func (m *Mobile) TurnOff() { - m.IsOn = false - fmt.Printf("%s %s is now turned off.\n", m.Brand, m.Model) -} - -// UseMobile simulates the usage of the mobile device. -func (m *Mobile) UseMobile(minutes int) { - if !m.IsOn { - fmt.Println("Please turn on the mobile device first.") - return - } - - if m.Battery <= 0 { - fmt.Println("The mobile device is out of battery. Please charge it.") - return - } - - m.LastUsage = time.Now() - fmt.Printf("Using %s %s for %d minutes.\n", m.Brand, m.Model, minutes) - - // Simulate battery drain - m.Battery -= minutes - if m.Battery < 0 { - m.Battery = 0 - } - - // Check battery level - if m.Battery == 0 { - m.TurnOff() - fmt.Println("The mobile device is out of battery. Please charge it.") - } -} - -// ChargeMobile charges the mobile device. -func (m *Mobile) ChargeMobile(minutes int) { - m.LastUsage = time.Now() - m.Battery += minutes - if m.Battery > 100 { - m.Battery = 100 - } - fmt.Printf("Charging %s %s for %d minutes.\n", m.Brand, m.Model, minutes) -} - -func main() { - // Create a new mobile device - myMobile := Mobile{ - Brand: "Apple", - Model: "iPhone X", - IsOn: false, - Battery: 50, - } - - // Turn on the mobile device - myMobile.TurnOn() - - // Simulate using the mobile device - myMobile.UseMobile(60) - - // Charge the mobile device - myMobile.ChargeMobile(30) - - // Simulate using the mobile device again - myMobile.UseMobile(120) - - // Turn off the mobile device - myMobile.TurnOff() -} From e58ba45238fb8a198745618de323b0ad4a38d829 Mon Sep 17 00:00:00 2001 From: Harjot Gill Date: Tue, 1 Aug 2023 12:48:01 -0700 Subject: [PATCH 08/11] removal only patches --- dist/index.js | 8 +++++--- src/review.ts | 12 ++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/dist/index.js b/dist/index.js index 9c72d149..e7f27904 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7935,6 +7935,7 @@ const parsePatch = (patch) => { const skipStart = 3; const skipEnd = 3; let currentLine = 0; + const removalOnly = !lines.some(line => line.startsWith('+')); for (const line of lines) { currentLine++; if (line.startsWith('-')) { @@ -7947,11 +7948,12 @@ const parsePatch = (patch) => { else { // context line oldHunkLines.push(`${line}`); - if (currentLine <= skipStart || currentLine > lines.length - skipEnd) { - newHunkLines.push(`${line}`); + if (removalOnly || + (currentLine > skipStart && currentLine <= lines.length - skipEnd)) { + newHunkLines.push(`${newLine}: ${line}`); } else { - newHunkLines.push(`${newLine}: ${line}`); + newHunkLines.push(`${line}`); } newLine++; } diff --git a/src/review.ts b/src/review.ts index 5376c049..422385f9 100644 --- a/src/review.ts +++ b/src/review.ts @@ -829,9 +829,10 @@ const parsePatch = ( let currentLine = 0 + const removalOnly = !lines.some(line => line.startsWith('+')) + for (const line of lines) { currentLine++ - if (line.startsWith('-')) { oldHunkLines.push(`${line.substring(1)}`) } else if (line.startsWith('+')) { @@ -840,10 +841,13 @@ const parsePatch = ( } else { // context line oldHunkLines.push(`${line}`) - if (currentLine <= skipStart || currentLine > lines.length - skipEnd) { - newHunkLines.push(`${line}`) - } else { + if ( + removalOnly || + (currentLine > skipStart && currentLine <= lines.length - skipEnd) + ) { newHunkLines.push(`${newLine}: ${line}`) + } else { + newHunkLines.push(`${line}`) } newLine++ } From d5f436db91a037848ba17aa93c868484e5d68ea8 Mon Sep 17 00:00:00 2001 From: Harjot Gill Date: Tue, 1 Aug 2023 12:48:23 -0700 Subject: [PATCH 09/11] test --- mobile.go | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 mobile.go diff --git a/mobile.go b/mobile.go new file mode 100644 index 00000000..befc75a8 --- /dev/null +++ b/mobile.go @@ -0,0 +1,91 @@ +package main + +import ( + "fmt" + "time" +) + +// Mobile struct represents a mobile device. +type Mobile struct { + Brand string + Model string + IsOn bool + Battery int + LastUsage time.Time +} + +// TurnOn turns on the mobile device. +func (m *Mobile) TurnOn() { + m.IsOn = true + m.LastUsage = time.Now() + fmt.Printf("%s %s is now turned on.\n", m.Brand, m.Model) +} + +// TurnOff turns off the mobile device. +func (m *Mobile) TurnOff() { + m.IsOn = false + fmt.Printf("%s %s is now turned off.\n", m.Brand, m.Model) +} + +// UseMobile simulates the usage of the mobile device. +func (m *Mobile) UseMobile(minutes int) { + if !m.IsOn { + fmt.Println("Please turn on the mobile device first.") + return + } + + if m.Battery <= 0 { + fmt.Println("The mobile device is out of battery. Please charge it.") + return + } + + m.LastUsage = time.Now() + fmt.Printf("Using %s %s for %d minutes.\n", m.Brand, m.Model, minutes) + + // Simulate battery drain + m.Battery -= minutes + if m.Battery < 0 { + m.Battery = 0 + } + + // Check battery level + if m.Battery == 0 { + m.TurnOff() + fmt.Println("The mobile device is out of battery. Please charge it.") + } +} + +// ChargeMobile charges the mobile device. +func (m *Mobile) ChargeMobile(minutes int) { + m.LastUsage = time.Now() + m.Battery += minutes + if m.Battery > 100 { + m.Battery = 100 + } + fmt.Printf("Charging %s %s for %d minutes.\n", m.Brand, m.Model, minutes) +} + +func main() { + // Create a new mobile device + myMobile := Mobile{ + Brand: "Apple", + Model: "iPhone X", + IsOn: false, + Battery: 50, + } + + // Turn on the mobile device + myMobile.TurnOn() + + // Simulate using the mobile device + myMobile.UseMobile(60) + + // Charge the mobile device + myMobile.ChargeMobile(30) + + // Simulate using the mobile device again + myMobile.UseMobile(120) + + // Turn off the mobile device + myMobile.TurnOff() +} From 315476ac7faef97d6b021c6624667af8393661c9 Mon Sep 17 00:00:00 2001 From: Harjot Gill Date: Tue, 1 Aug 2023 13:03:55 -0700 Subject: [PATCH 10/11] test --- dist/index.js | 11 +++++------ mobile.go | 2 +- src/prompts.ts | 11 +++++------ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/dist/index.js b/dist/index.js index e7f27904..1c2c43c3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6844,12 +6844,11 @@ format \`\`. hunks. Multiple new code snippets are allowed within a single review section. - If needed, provide replacement code suggestions to fix the issues by using fenced code blocks with the \`suggestion\` as the language identifier. The - and must map exactly to the subset range - of lines (inclusive) that needs to be replaced within a new hunk. For instance, - if 2 lines of code in a hunk need to be replaced with 15 lines of code, the - line number range must be those exact 2 lines. All the lines between - and must be completely replaced by the - suggestion. Replacement suggestions should be complete, correctly + line number range must map exactly to the range (inclusive) that needs to + be replaced within a new hunk. For instance, if 2 lines of code in a hunk + need to be replaced with 15 lines of code, the line number range must be + those exact 2 lines. You must replace all the lines in the range with your + suggestion. Replacement suggestions must be complete, correctly formatted/indented and without the line number annotations. - If there are no issues found on a line range, you MUST respond with the text \`LGTM!\` for that line range in the review section. diff --git a/mobile.go b/mobile.go index befc75a8..504d3eea 100644 --- a/mobile.go +++ b/mobile.go @@ -55,7 +55,7 @@ func (m *Mobile) UseMobile(minutes int) { } } -// ChargeMobile charges the mobile device. +// ChargeMobile charges the mobile device func (m *Mobile) ChargeMobile(minutes int) { m.LastUsage = time.Now() m.Battery += minutes diff --git a/src/prompts.ts b/src/prompts.ts index f95f5d48..dc3c09f2 100644 --- a/src/prompts.ts +++ b/src/prompts.ts @@ -170,12 +170,11 @@ format \`\`. hunks. Multiple new code snippets are allowed within a single review section. - If needed, provide replacement code suggestions to fix the issues by using fenced code blocks with the \`suggestion\` as the language identifier. The - and must map exactly to the subset range - of lines (inclusive) that needs to be replaced within a new hunk. For instance, - if 2 lines of code in a hunk need to be replaced with 15 lines of code, the - line number range must be those exact 2 lines. All the lines between - and must be completely replaced by the - suggestion. Replacement suggestions should be complete, correctly + line number range must map exactly to the range (inclusive) that needs to + be replaced within a new hunk. For instance, if 2 lines of code in a hunk + need to be replaced with 15 lines of code, the line number range must be + those exact 2 lines. You must replace all the lines in the range with your + suggestion. Replacement suggestions must be complete, correctly formatted/indented and without the line number annotations. - If there are no issues found on a line range, you MUST respond with the text \`LGTM!\` for that line range in the review section. From 2752af0d83ef74d1f1dd7dc130d5d04da8ad23bc Mon Sep 17 00:00:00 2001 From: Harjot Gill Date: Tue, 1 Aug 2023 13:08:22 -0700 Subject: [PATCH 11/11] test --- mobile.go | 91 ------------------------------------------------------- 1 file changed, 91 deletions(-) delete mode 100644 mobile.go diff --git a/mobile.go b/mobile.go deleted file mode 100644 index 504d3eea..00000000 --- a/mobile.go +++ /dev/null @@ -1,91 +0,0 @@ -package main - -import ( - "fmt" - "time" -) - -// Mobile struct represents a mobile device. -type Mobile struct { - Brand string - Model string - IsOn bool - Battery int - LastUsage time.Time -} - -// TurnOn turns on the mobile device. -func (m *Mobile) TurnOn() { - m.IsOn = true - m.LastUsage = time.Now() - fmt.Printf("%s %s is now turned on.\n", m.Brand, m.Model) -} - -// TurnOff turns off the mobile device. -func (m *Mobile) TurnOff() { - m.IsOn = false - fmt.Printf("%s %s is now turned off.\n", m.Brand, m.Model) -} - -// UseMobile simulates the usage of the mobile device. -func (m *Mobile) UseMobile(minutes int) { - if !m.IsOn { - fmt.Println("Please turn on the mobile device first.") - return - } - - if m.Battery <= 0 { - fmt.Println("The mobile device is out of battery. Please charge it.") - return - } - - m.LastUsage = time.Now() - fmt.Printf("Using %s %s for %d minutes.\n", m.Brand, m.Model, minutes) - - // Simulate battery drain - m.Battery -= minutes - if m.Battery < 0 { - m.Battery = 0 - } - - // Check battery level - if m.Battery == 0 { - m.TurnOff() - fmt.Println("The mobile device is out of battery. Please charge it.") - } -} - -// ChargeMobile charges the mobile device -func (m *Mobile) ChargeMobile(minutes int) { - m.LastUsage = time.Now() - m.Battery += minutes - if m.Battery > 100 { - m.Battery = 100 - } - fmt.Printf("Charging %s %s for %d minutes.\n", m.Brand, m.Model, minutes) -} - -func main() { - // Create a new mobile device - myMobile := Mobile{ - Brand: "Apple", - Model: "iPhone X", - IsOn: false, - Battery: 50, - } - - // Turn on the mobile device - myMobile.TurnOn() - - // Simulate using the mobile device - myMobile.UseMobile(60) - - // Charge the mobile device - myMobile.ChargeMobile(30) - - // Simulate using the mobile device again - myMobile.UseMobile(120) - - // Turn off the mobile device - myMobile.TurnOff() -}