@@ -130,36 +130,6 @@ const buildReviewInput = (
130130 return parts . join ( "\n" ) ;
131131} ;
132132
133- const firstChangedPosition = ( patch : string ) : number => {
134- if ( ! patch ) return 1 ;
135- const lines = patch . split ( "\n" ) ;
136-
137- const start = lines . findIndex ( ( l ) => l . startsWith ( "@@ " ) ) ;
138- if ( start === - 1 ) {
139- const firstNonEmpty = lines . findIndex ( ( l ) => l . trim ( ) . length > 0 ) ;
140- return Math . max ( 1 , ( firstNonEmpty === - 1 ? 0 : firstNonEmpty ) + 1 ) ;
141- }
142-
143- for ( let i = start + 1 ; i < lines . length ; i ++ ) {
144- const line = lines [ i ] ;
145- if ( line . startsWith ( "+" ) && ! line . startsWith ( "+++" ) ) {
146- return Math . min ( Math . max ( 1 , i + 1 ) , lines . length ) ;
147- }
148- if ( line . startsWith ( "@@ " ) ) break ; // stop at next hunk header
149- }
150-
151- // fall back to the first context line within the first hunk.
152- for ( let i = start + 1 ; i < lines . length ; i ++ ) {
153- const line = lines [ i ] ;
154- if ( line . startsWith ( " " ) ) {
155- return Math . min ( Math . max ( 1 , i + 1 ) , lines . length ) ;
156- }
157- if ( line . startsWith ( "@@ " ) ) break ;
158- }
159-
160- return Math . min ( Math . max ( 1 , start + 2 ) , lines . length ) ;
161- } ;
162-
163133const REVIEW_ON_LGTM = process . env . REVIEW_ON_LGTM === "true" ? true : false ;
164134
165135export const robot = ( app : Probot ) => {
@@ -250,18 +220,7 @@ export const robot = (app: Probot) => {
250220 log . debug ( "compareCommits.files" , changedFiles ) ;
251221
252222 let hasSummaryReview = false ;
253- if ( context . payload . action === "synchronize" && commits . length >= 2 ) {
254- const {
255- data : { files } ,
256- } = await context . octokit . repos . compareCommits ( {
257- owner : repo . owner ,
258- repo : repo . repo ,
259- base : commits [ commits . length - 2 ] . sha ,
260- head : commits [ commits . length - 1 ] . sha ,
261- } ) ;
262-
263- changedFiles = files ;
264-
223+ if ( context . payload . action === "synchronize" ) {
265224 const reviews = await context . octokit . pulls . listReviews ( {
266225 owner : repo . owner ,
267226 repo : repo . repo ,
@@ -452,10 +411,13 @@ export const robot = (app: Probot) => {
452411
453412 try {
454413 const res = await chat ?. codeReview ( reviewInput ) ;
455- console . log ( "res.lgtm" , res . lgtm ) ;
456- console . log ( "res.review_comment" , res . review_comment ) ;
414+ if ( ! res ) {
415+ continue ;
416+ }
417+ log . debug ( "res.lgtm" , res . lgtm ) ;
418+ log . debug ( "res.comments" , res . comments ) ;
457419
458- if ( ! ! ! res . review_comment ) {
420+ if ( ! res . comments || res . comments . length === 0 ) {
459421 continue ;
460422 }
461423
@@ -464,32 +426,32 @@ export const robot = (app: Probot) => {
464426 log . info (
465427 `PR 파일에 patch가 없어 ${ file . filename } 에 대한 코멘트 생략`
466428 ) ;
467- inlineFallback . push (
468- `\n### ${ file . filename } \n${ res . review_comment } `
469- ) ;
429+ const fallbackBody = res . comments . map ( ( c ) => c . body ) . join ( "\n" ) ;
430+ inlineFallback . push ( `\n### ${ file . filename } \n${ fallbackBody } ` ) ;
470431 continue ;
471432 }
472- // Compute position against the PR-wide patch to avoid misalignment
433+
473434 const prWidePatch = prFilePatchByPath . get ( file . filename ) || patch ;
474435 if ( ! prWidePatch || ! prWidePatch . includes ( "@@" ) ) {
475- inlineFallback . push (
476- `\n### ${ file . filename } \n${ res . review_comment } `
477- ) ;
436+ const fallbackBody = res . comments . map ( ( c ) => c . body ) . join ( "\n" ) ;
437+ inlineFallback . push ( `\n### ${ file . filename } \n${ fallbackBody } ` ) ;
478438 continue ;
479439 }
480440
481- const position = firstChangedPosition ( prWidePatch ) ;
482- if ( ! Number . isSafeInteger ( position ) || position <= 0 ) {
483- inlineFallback . push (
484- `\n### ${ file . filename } \n${ res . review_comment } `
485- ) ;
486- continue ;
441+ for ( const comment of res . comments ) {
442+ const position = comment . line ;
443+ if ( ! Number . isSafeInteger ( position ) || position <= 0 ) {
444+ inlineFallback . push (
445+ `\n### ${ file . filename } \n${ comment . body } `
446+ ) ;
447+ continue ;
448+ }
449+ ress . push ( {
450+ path : file . filename ,
451+ body : comment . body ,
452+ position,
453+ } ) ;
487454 }
488- ress . push ( {
489- path : file . filename ,
490- body : res . review_comment ,
491- position,
492- } ) ;
493455 }
494456 } catch ( e : any ) {
495457 const status = e ?. status || e ?. response ?. status ;
0 commit comments