@@ -2,6 +2,7 @@ import { getConfig } from "../config.js";
22import { reviewDiff } from "../review/reviewer.js" ;
33import { GitHubClient } from "./client.js" ;
44import { CHECK_STATUS , CHECK_CONCLUSION , PRDetails , GitHubPullRequestEvent } from "./types.js" ;
5+ import { startReviewSession , endReviewSession } from "../review/comment-collector.js" ;
56
67export async function processReview (
78 jobId : string ,
@@ -61,24 +62,61 @@ export async function processReview(
6162
6263 const prDetailsContent = `Repository: ${ payload . repository . full_name } , PR Number: ${ prDetails . pr_number } , Commit SHA: ${ prDetails . commit_sha } , PR URL: ${ prDetails . pr_url } ` ;
6364
65+ console . log ( `Starting review session for job ${ jobId } ` ) ;
66+ const sessionId = `session-${ jobId } ` ;
67+ startReviewSession ( sessionId ) ;
68+
6469 console . log ( `Calling reviewDiff() for job ${ jobId } ` ) ;
65- const reviewResult = await reviewDiff ( diffContent , prDetailsContent , installationId ) ;
70+ await reviewDiff ( diffContent , prDetailsContent , installationId , sessionId ) ;
6671 console . log ( `Review completed for job ${ jobId } ` ) ;
6772
68- // Update check run with success
73+ // Collect all comments from the review session
74+ const collector = endReviewSession ( sessionId ) ;
75+ console . log ( `Collected ${ collector . getInlineComments ( ) . length } inline comments and ${ collector . getGeneralComments ( ) . length } general comments` ) ;
76+
77+ // Post aggregated review if there are any comments
78+ if ( collector . hasComments ( ) ) {
79+ console . log ( '📋 Posting aggregated PR review...' ) ;
80+ const reviewSummary = collector . getReviewSummary ( ) ;
81+ const inlineComments = collector . getInlineComments ( ) ;
82+
83+ await githubClient . createPRReview (
84+ owner ,
85+ repo ,
86+ prNumber ,
87+ reviewSummary ,
88+ 'COMMENT' ,
89+ inlineComments . map ( comment => ( {
90+ path : comment . path ,
91+ line : comment . line ,
92+ body : comment . body
93+ } ) )
94+ ) ;
95+ console . log ( '✅ PR review posted successfully' ) ;
96+ }
97+
98+ // Update check run with success (simplified since review details are now in PR review)
6999 await githubClient . updateCheckRun ( owner , repo , checkRun . id , {
70100 status : CHECK_STATUS . COMPLETED ,
71101 conclusion : CHECK_CONCLUSION . SUCCESS ,
72102 output : {
73103 title : 'Code Review Completed' ,
74- summary : 'Code review has been completed successfully.' ,
75- text : reviewResult . result || 'Review completed successfully.' ,
104+ summary : 'Code review has been completed successfully. See PR conversation for details.' ,
76105 } ,
77106 details_url : prUrl ,
78107 } ) ;
79108
80109 } catch ( error ) {
81110 console . error ( `Review job ${ jobId } failed with exception:` , error ) ;
111+
112+ // End review session if it was started
113+ try {
114+ const sessionId = `session-${ jobId } ` ;
115+ endReviewSession ( sessionId ) ;
116+ } catch {
117+ console . log ( 'No active review session to end' ) ;
118+ }
119+
82120 // Post FAILED check run for exceptions
83121 await postFailureCheckRun ( githubClient , payload , error instanceof Error ? error . message : String ( error ) ) ;
84122 }
0 commit comments