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

Commit 775a555

Browse files
authored
fix suggestions (#196)
1 parent 94fc36e commit 775a555

File tree

2 files changed

+46
-44
lines changed

2 files changed

+46
-44
lines changed

dist/index.js

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

src/review.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -871,32 +871,36 @@ function parseReview(
871871
function removeLineNumbersFromSuggestion(comment: string): string {
872872
const suggestionStart = '```suggestion'
873873
const suggestionEnd = '```'
874-
const suggestionStartIndex = comment.indexOf(suggestionStart)
874+
let suggestionStartIndex = comment.indexOf(suggestionStart)
875875

876-
if (suggestionStartIndex === -1) {
877-
return comment
878-
}
876+
while (suggestionStartIndex !== -1) {
877+
const suggestionEndIndex = comment.indexOf(
878+
suggestionEnd,
879+
suggestionStartIndex
880+
)
881+
const suggestionBlock = comment.substring(
882+
suggestionStartIndex + suggestionStart.length,
883+
suggestionEndIndex
884+
)
885+
const lineNumberRegex = /^\s*\d+:\s+/
879886

880-
const suggestionEndIndex = comment.indexOf(
881-
suggestionEnd,
882-
suggestionStartIndex
883-
)
884-
const suggestionBlock = comment.substring(
885-
suggestionStartIndex + suggestionStart.length,
886-
suggestionEndIndex
887-
)
888-
const lineNumberRegex = /^\s*\d+:\s+/
887+
const sanitizedBlock = suggestionBlock
888+
.split('\n')
889+
.map(line => line.replace(lineNumberRegex, ''))
890+
.join('\n')
889891

890-
const sanitizedBlock = suggestionBlock
891-
.split('\n')
892-
.map(line => line.replace(lineNumberRegex, ''))
893-
.join('\n')
892+
comment =
893+
comment.substring(0, suggestionStartIndex + suggestionStart.length) +
894+
sanitizedBlock +
895+
comment.substring(suggestionEndIndex)
894896

895-
return (
896-
comment.substring(0, suggestionStartIndex + suggestionStart.length) +
897-
sanitizedBlock +
898-
comment.substring(suggestionEndIndex)
899-
)
897+
suggestionStartIndex = comment.indexOf(
898+
suggestionStart,
899+
suggestionEndIndex + suggestionEnd.length
900+
)
901+
}
902+
903+
return comment
900904
}
901905

902906
function storeReview(): void {
@@ -944,11 +948,9 @@ ${review.comment}`
944948

945949
reviews.push(review)
946950

947-
if (debug) {
948-
core.info(
949-
`Stored comment for line range ${currentStartLine}-${currentEndLine}: ${currentComment.trim()}`
950-
)
951-
}
951+
core.info(
952+
`Stored comment for line range ${currentStartLine}-${currentEndLine}: ${currentComment.trim()}`
953+
)
952954
}
953955
}
954956

0 commit comments

Comments
 (0)