Skip to content

Commit

Permalink
Update prompts (coderabbitai#408)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by OSS CodeRabbit
-->
### Summary by CodeRabbit

**New Feature:**
- Introduced a `Mobile` struct in `mobile.go` to simulate the behavior
of a mobile device with methods for turning on/off, usage, and charging.
- Enhanced code snippets and instructions for providing replacement code
suggestions in `src/prompts.ts`.
- Improved parsing functionality in `src/review.ts` to handle context
lines and skip annotations for the first 3 and last 3 lines.
- Added a new section in the PR description promoting the Pro version of
the project.

> 🎉 Code's evolving, growing so fine, 🌱
> 
> With every pull request, it shines. ✨
> 
> Mobile simulation, parsing delight, 📱🎁
> 
> Our codebase takes an exciting flight! 🚀
<!-- end of auto-generated comment: release notes by OSS CodeRabbit -->
  • Loading branch information
harjotgill authored Aug 1, 2023
1 parent 6e65620 commit 9a257da
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 28 deletions.
41 changes: 27 additions & 14 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 9 additions & 10 deletions src/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,9 @@ format \`<line_number><colon><whitespace>\`.
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.
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.
- Reflect on your comments and line number ranges before sending the final
Expand Down Expand Up @@ -207,18 +206,18 @@ format \`<line_number><colon><whitespace>\`.
---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---
Expand Down
26 changes: 22 additions & 4 deletions src/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 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.
</details>
`

Expand Down Expand Up @@ -810,7 +814,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
Expand All @@ -820,17 +823,32 @@ const parsePatch = (
lines.pop()
}

// Skip annotations for the first 3 and last 3 lines
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('-')) {
oldHunkLines.push(`${line.substring(1)}`)
// old_line++
} else if (line.startsWith('+')) {
newHunkLines.push(`${newLine}: ${line.substring(1)}`)
newLine++
} else {
// context line
oldHunkLines.push(`${line}`)
newHunkLines.push(`${newLine}: ${line}`)
// old_line++
if (
removalOnly ||
(currentLine > skipStart && currentLine <= lines.length - skipEnd)
) {
newHunkLines.push(`${newLine}: ${line}`)
} else {
newHunkLines.push(`${line}`)
}
newLine++
}
}
Expand Down

0 comments on commit 9a257da

Please sign in to comment.