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

sanitize review start_line/end_line #189

Merged
merged 4 commits into from
Apr 18, 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
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,
harjotgill marked this conversation as resolved.
Show resolved Hide resolved
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
}
harjotgill marked this conversation as resolved.
Show resolved Hide resolved

// sanitize review's start_line and end_line
// with patches' start_line and end_line
// if needed adjust start_line and end_line
harjotgill marked this conversation as resolved.
Show resolved Hide resolved
harjotgill marked this conversation as resolved.
Show resolved Hide resolved
harjotgill marked this conversation as resolved.
Show resolved Hide resolved
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
}
}
harjotgill marked this conversation as resolved.
Show resolved Hide resolved
}

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}]
harjotgill marked this conversation as resolved.
Show resolved Hide resolved

${review.comment}`
review.start_line = closest_start_line
review.end_line = closest_end_line
Expand Down