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

Commit

Permalink
sanitize review start_line/end_line (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
harjotgill authored Apr 18, 2023
1 parent a660474 commit 0c69ed0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 16 deletions.
46 changes: 39 additions & 7 deletions dist/index.js

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

22 changes: 14 additions & 8 deletions src/commenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ ${tag}`
${message}
${tag}`

this.reviewCommentsBuffer.push({
path,
start_line,
Expand All @@ -166,13 +165,20 @@ ${tag}`
pull_number,
commit_id,
event: 'COMMENT',
comments: this.reviewCommentsBuffer.map(comment => ({
path: comment.path,
body: comment.message,
line: comment.end_line,
start_line: comment.start_line,
start_side: 'RIGHT'
}))
comments: this.reviewCommentsBuffer.map(comment => {
const commentData: any = {
path: comment.path,
body: comment.message,
line: comment.end_line,
start_side: 'RIGHT'
}

if (comment.start_line !== comment.end_line) {
commentData.start_line = comment.start_line
}

return commentData
})
})
this.reviewCommentsBuffer = []
}
Expand Down
8 changes: 7 additions & 1 deletion src/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ ${comment_chain}
core.warning('No pull request found, skipping.')
continue
}

// sanitize review's start_line and end_line
// with patches' start_line and end_line
// if needed adjust start_line and end_line
Expand All @@ -621,15 +622,20 @@ ${comment_chain}
if (review.start_line >= start_line) {
closest_start_line = start_line
closest_end_line = end_line
if (review.end_line <= end_line) {
if (
review.end_line <= end_line &&
review.end_line >= start_line
) {
within_patch = true
break
}
}
}

if (!within_patch) {
// map the review to the closest patch
review.comment = `> Note: This review was outside of the patch, so it was mapped it to the closest patch. Original lines [${review.start_line}-${review.end_line}]
${review.comment}`
review.start_line = closest_start_line
review.end_line = closest_end_line
Expand Down

0 comments on commit 0c69ed0

Please sign in to comment.