@@ -517,6 +517,46 @@ export const detectSSHError = (output: string): string | undefined => {
517517 return `SSH test failed: ${ output . substring ( 0 , 200 ) } ` ;
518518} ;
519519
520+ const getPullRequestReviewComments = async (
521+ directoryPath : string ,
522+ prNumber : number ,
523+ ) : Promise < any > => {
524+ // Validate prNumber: must be a positive integer
525+ if (
526+ typeof prNumber !== "number" ||
527+ ! Number . isInteger ( prNumber ) ||
528+ prNumber < 1
529+ ) {
530+ throw new Error ( `Invalid pull request number: ${ prNumber } ` ) ;
531+ }
532+
533+ try {
534+ // Extract repo from remote URL (format: owner/repo)
535+ const remoteUrl = await getRemoteUrl ( directoryPath ) ;
536+ if ( ! remoteUrl ) {
537+ throw new Error ( "No remote URL found" ) ;
538+ }
539+
540+ // Parse repo from URL (handles both HTTPS and SSH formats)
541+ const repoMatch = remoteUrl . match (
542+ / g i t h u b \. c o m [: / ] ( [ ^ / ] + \/ [ ^ / ] + ?) (?: \. g i t ) ? $ / ,
543+ ) ;
544+ if ( ! repoMatch ) {
545+ throw new Error ( `Cannot parse repository from URL: ${ remoteUrl } ` ) ;
546+ }
547+ const repo = repoMatch [ 1 ] ;
548+
549+ // TODO: Paginate if many comments
550+ const { stdout } = await execAsync (
551+ `gh api repos/${ repo } /pulls/${ prNumber } /comments` ,
552+ { cwd : directoryPath } ,
553+ ) ;
554+ return JSON . parse ( stdout ) ;
555+ } catch ( error ) {
556+ throw new Error ( `Failed to fetch PR review comments: ${ error } ` ) ;
557+ }
558+ } ;
559+
520560export function registerGitIpc (
521561 getMainWindow : ( ) => BrowserWindow | null ,
522562) : void {
@@ -796,4 +836,15 @@ export function registerGitIpc(
796836 return discardFileChanges ( directoryPath , filePath , fileStatus ) ;
797837 } ,
798838 ) ;
839+
840+ ipcMain . handle (
841+ "get-pr-review-comments" ,
842+ async (
843+ _event : IpcMainInvokeEvent ,
844+ directoryPath : string ,
845+ prNumber : number ,
846+ ) : Promise < any > => {
847+ return getPullRequestReviewComments ( directoryPath , prNumber ) ;
848+ } ,
849+ ) ;
799850}
0 commit comments