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

Commit 0c69ed0

Browse files
authored
sanitize review start_line/end_line (#189)
1 parent a660474 commit 0c69ed0

File tree

3 files changed

+60
-16
lines changed

3 files changed

+60
-16
lines changed

dist/index.js

Lines changed: 39 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commenter.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ ${tag}`
148148
${message}
149149
150150
${tag}`
151-
152151
this.reviewCommentsBuffer.push({
153152
path,
154153
start_line,
@@ -166,13 +165,20 @@ ${tag}`
166165
pull_number,
167166
commit_id,
168167
event: 'COMMENT',
169-
comments: this.reviewCommentsBuffer.map(comment => ({
170-
path: comment.path,
171-
body: comment.message,
172-
line: comment.end_line,
173-
start_line: comment.start_line,
174-
start_side: 'RIGHT'
175-
}))
168+
comments: this.reviewCommentsBuffer.map(comment => {
169+
const commentData: any = {
170+
path: comment.path,
171+
body: comment.message,
172+
line: comment.end_line,
173+
start_side: 'RIGHT'
174+
}
175+
176+
if (comment.start_line !== comment.end_line) {
177+
commentData.start_line = comment.start_line
178+
}
179+
180+
return commentData
181+
})
176182
})
177183
this.reviewCommentsBuffer = []
178184
}

src/review.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ ${comment_chain}
609609
core.warning('No pull request found, skipping.')
610610
continue
611611
}
612+
612613
// sanitize review's start_line and end_line
613614
// with patches' start_line and end_line
614615
// if needed adjust start_line and end_line
@@ -621,15 +622,20 @@ ${comment_chain}
621622
if (review.start_line >= start_line) {
622623
closest_start_line = start_line
623624
closest_end_line = end_line
624-
if (review.end_line <= end_line) {
625+
if (
626+
review.end_line <= end_line &&
627+
review.end_line >= start_line
628+
) {
625629
within_patch = true
626630
break
627631
}
628632
}
629633
}
634+
630635
if (!within_patch) {
631636
// map the review to the closest patch
632637
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}]
638+
633639
${review.comment}`
634640
review.start_line = closest_start_line
635641
review.end_line = closest_end_line

0 commit comments

Comments
 (0)