@@ -869,10 +869,11 @@ function parseReview(
869
869
let currentComment = ''
870
870
function storeReview ( ) : void {
871
871
if ( currentStartLine !== null && currentEndLine !== null ) {
872
+ const sanitizedComment = sanitizeComment ( currentComment . trim ( ) )
872
873
const review : Review = {
873
874
start_line : currentStartLine ,
874
875
end_line : currentEndLine ,
875
- comment : currentComment . trim ( )
876
+ comment : sanitizedComment . trim ( )
876
877
}
877
878
878
879
let within_patch = false
@@ -915,6 +916,44 @@ ${review.comment}`
915
916
}
916
917
}
917
918
919
+ function sanitizeComment ( comment : string ) : string {
920
+ const suggestionStart = '```suggestion'
921
+ const suggestionEnd = '```'
922
+ const lineNumberRegex = / ^ * ( \d + ) : / gm
923
+
924
+ let suggestionStartIndex = comment . indexOf ( suggestionStart )
925
+
926
+ while ( suggestionStartIndex !== - 1 ) {
927
+ const suggestionEndIndex = comment . indexOf (
928
+ suggestionEnd ,
929
+ suggestionStartIndex + suggestionStart . length
930
+ )
931
+
932
+ if ( suggestionEndIndex === - 1 ) break
933
+
934
+ const suggestionBlock = comment . substring (
935
+ suggestionStartIndex + suggestionStart . length ,
936
+ suggestionEndIndex
937
+ )
938
+ const sanitizedBlock = suggestionBlock . replace ( lineNumberRegex , '' )
939
+
940
+ comment =
941
+ comment . slice ( 0 , suggestionStartIndex + suggestionStart . length ) +
942
+ sanitizedBlock +
943
+ comment . slice ( suggestionEndIndex )
944
+
945
+ suggestionStartIndex = comment . indexOf (
946
+ suggestionStart ,
947
+ suggestionStartIndex +
948
+ suggestionStart . length +
949
+ sanitizedBlock . length +
950
+ suggestionEnd . length
951
+ )
952
+ }
953
+
954
+ return comment
955
+ }
956
+
918
957
for ( const line of lines ) {
919
958
const lineNumberRangeMatch = line . match ( lineNumberRangeRegex )
920
959
0 commit comments