@@ -34,43 +34,50 @@ export function resolveHunkReferencesInComments(comments: AiReview["comments"],
3434 core . warning ( `Could not find file for comment on ${ comment . path } , start ${ comment . start } , end ${ comment . end } , ${ comment . comment } , skipping.` )
3535 } else {
3636 const hunkChangeMap = currentFile . chunks . flatMap ( hunk => hunk . changes . map ( change => ( { change, hunk } ) ) )
37- let { change : startChange , hunk : startHunk } = hunkChangeMap [ comment . start - 1 ] // eslint-disable-line prefer-const
38- let { change : endChange , hunk : endHunk } = hunkChangeMap [ comment . end - 1 ] // eslint-disable-line prefer-const
37+ const startEntry = hunkChangeMap [ comment . start - 1 ]
38+ const endEntry = hunkChangeMap [ comment . end - 1 ]
3939
40- if ( ! startHunk ) {
41- core . warning ( `Could not find hunk for comment on ${ comment . path } , start ${ comment . start } , end ${ comment . end } , ${ comment . comment } , skipping.` )
40+ if ( ! startEntry || ! endEntry ) {
41+ core . error ( `Could not find hunk for comment on ${ comment . path } , start ${ comment . start } , end ${ comment . end } , ${ comment . comment } , skipping.` )
4242 } else {
43- if ( startHunk !== endHunk ) endChange = startHunk . changes . at ( - 1 ) !
43+ const { change : startChange , hunk : startHunk } = startEntry
44+ let { change : endChange , hunk : endHunk } = endEntry // eslint-disable-line prefer-const
4445
45- const startSide = startChange . type !== "del" ? "RIGHT" : "LEFT"
46- const endSide = endChange . type !== "del" ? "RIGHT" : "LEFT"
46+ if ( ! startHunk ) {
47+ core . warning ( `Could not find hunk for comment on ${ comment . path } , start ${ comment . start } , end ${ comment . end } , ${ comment . comment } , skipping.` )
48+ } else {
49+ if ( startHunk !== endHunk ) endChange = startHunk . changes . at ( - 1 ) !
4750
48- // get start line of the actual comment
49- let start : number
50- if ( startChange . type === "normal" ) {
51- start = startChange . ln2
52- } else if ( startChange . type === "add" || startChange . type === "del" ) {
53- start = startChange . ln
54- } else throw new Error ( `Unknown change type.` )
51+ const startSide = startChange . type !== "del" ? "RIGHT" : "LEFT"
52+ const endSide = endChange . type !== "del" ? "RIGHT" : "LEFT"
5553
56- // get end line of the actual comment
57- let end : number
58- if ( endChange . type === "normal" ) {
59- end = endChange . ln2
60- } else if ( endChange . type === "add" || endChange . type === "del" ) {
61- end = endChange . ln
62- } else throw new Error ( `Unknown change type.` )
63- // make sure start and end are within the hunk
64- end = Math . min ( end , endSide === "RIGHT" ? startHunk . newStart + startHunk . newLines - 1 : startHunk . oldStart + startHunk . oldLines - 1 )
54+ // get start line of the actual comment
55+ let start : number
56+ if ( startChange . type === "normal" ) {
57+ start = startChange . ln2
58+ } else if ( startChange . type === "add" || startChange . type === "del" ) {
59+ start = startChange . ln
60+ } else throw new Error ( `Unknown change type.` )
6561
66- result . push ( {
67- path : comment . path ,
68- start_side : startSide !== endSide ? startSide : undefined , // only set start_side if it is a multi-line comment
69- side : startSide !== endSide ? endSide : startSide ,
70- start_line : start !== end && start < end ? start : undefined , // only set start_line if it is a multi-line comment, start must be less than end
71- line : start !== end && start < end ? end : start ,
72- body : comment . comment ,
73- } )
62+ // get end line of the actual comment
63+ let end : number
64+ if ( endChange . type === "normal" ) {
65+ end = endChange . ln2
66+ } else if ( endChange . type === "add" || endChange . type === "del" ) {
67+ end = endChange . ln
68+ } else throw new Error ( `Unknown change type.` )
69+ // make sure start and end are within the hunk
70+ end = Math . min ( end , endSide === "RIGHT" ? startHunk . newStart + startHunk . newLines - 1 : startHunk . oldStart + startHunk . oldLines - 1 )
71+
72+ result . push ( {
73+ path : comment . path ,
74+ start_side : startSide !== endSide ? startSide : undefined , // only set start_side if it is a multi-line comment
75+ side : startSide !== endSide ? endSide : startSide ,
76+ start_line : start !== end && start < end ? start : undefined , // only set start_line if it is a multi-line comment, start must be less than end
77+ line : start !== end && start < end ? end : start ,
78+ body : comment . comment ,
79+ } )
80+ }
7481 }
7582 }
7683 } )
0 commit comments