Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

single line comments #411

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions dist/index.js

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

6 changes: 3 additions & 3 deletions src/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ The format for changes provided below consists of multiple change
sections, each containing a new hunk (annotated with line numbers),
an old hunk, and optionally, existing comment chains. Note that the
old hunk code has been replaced by the new hunk. The line number
annotation on each line in the new hunk is of the
format \`<line_number><colon><whitespace>\`.
annotation on some lines in the new hunk is of the format
\`<line_number><colon><whitespace>\`.

### Format for changes

Expand Down Expand Up @@ -143,7 +143,7 @@ format \`<line_number><colon><whitespace>\`.
strong evidence within the provided context to suggest there might be a problem.
- Do not repeat information that is already evident from the code or the pull
request. Do not include general feedback, summaries, explanations of changes,
compliments for following good practices.
and/or compliments for following good practices.
- Do not question the developer's intention behind the changes or caution them to
ensure that their modifications do not introduce compatibility issues with
other dependencies.
Expand Down
11 changes: 11 additions & 0 deletions src/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ function parseReview(

const lines = response.split('\n')
const lineNumberRangeRegex = /(?:^|\s)(\d+)-(\d+):\s*$/
const lineNumberSingleRegex = /(?:^|\s)(\d+):\s*$/ // New single line regex
const commentSeparator = '---'

let currentStartLine: number | null = null
Expand Down Expand Up @@ -976,6 +977,7 @@ ${review.comment}`

for (const line of lines) {
const lineNumberRangeMatch = line.match(lineNumberRangeRegex)
const lineNumberSingleMatch = line.match(lineNumberSingleRegex) // Check for single line match

if (lineNumberRangeMatch != null) {
storeReview()
Expand All @@ -986,6 +988,15 @@ ${review.comment}`
info(`Found line number range: ${currentStartLine}-${currentEndLine}`)
}
continue
} else if (lineNumberSingleMatch != null) {
storeReview()
currentStartLine = parseInt(lineNumberSingleMatch[1], 10)
currentEndLine = currentStartLine // For single line comments, start and end are the same
currentComment = ''
if (debug) {
info(`Found single line comment: ${currentStartLine}`)
}
continue
}

if (line.trim() === commentSeparator) {
Expand Down