@@ -19,7 +19,7 @@ import { asTempStorageURI, fromPRUri, fromReviewUri, Schemes, toPRUri } from './
1919import { formatError } from './common/utils' ;
2020import { EXTENSION_ID } from './constants' ;
2121import { ICopilotRemoteAgentCommandArgs } from './github/common' ;
22- import { ChatSessionWithPR } from './github/copilotApi' ;
22+ import { ChatSessionWithPR , CrossChatSessionWithPR } from './github/copilotApi' ;
2323import { CopilotRemoteAgentManager } from './github/copilotRemoteAgent' ;
2424import { FolderRepositoryManager } from './github/folderRepositoryManager' ;
2525import { GitHubRepository } from './github/githubRepository' ;
@@ -198,6 +198,11 @@ function isChatSessionWithPR(value: any): value is ChatSessionWithPR {
198198 return ! ! asChatSessionWithPR . pullRequest ;
199199}
200200
201+ function isCrossChatSessionWithPR ( value : any ) : value is CrossChatSessionWithPR {
202+ const asCrossChatSessionWithPR = value as Partial < CrossChatSessionWithPR > ;
203+ return ! ! asCrossChatSessionWithPR . pullRequestDetails ;
204+ }
205+
201206export function registerCommands (
202207 context : vscode . ExtensionContext ,
203208 reposManager : RepositoriesManager ,
@@ -566,7 +571,7 @@ export function registerCommands(
566571 return { folderManager, pr } ;
567572 } ;
568573
569- const applyPullRequestChanges = async ( folderManager : FolderRepositoryManager , pullRequest : PullRequestModel ) : Promise < void > => {
574+ const applyPullRequestChanges = async ( task : vscode . Progress < { message ?: string ; increment ?: number ; } > , folderManager : FolderRepositoryManager , pullRequest : PullRequestModel ) : Promise < void > => {
570575 let patch : string | undefined ;
571576 try {
572577 patch = await pullRequest . getPatch ( ) ;
@@ -584,22 +589,13 @@ export function registerCommands(
584589 const encoder = new TextEncoder ( ) ;
585590 const tempUri = vscode . Uri . file ( tempFilePath ) ;
586591
587- await vscode . window . withProgress (
588- {
589- location : vscode . ProgressLocation . Notification ,
590- title : vscode . l10n . t ( 'Applying changes from pull request #{0}' , pullRequest . number . toString ( ) ) ,
591- cancellable : false
592- } ,
593- async ( task ) => {
594- await vscode . workspace . fs . writeFile ( tempUri , encoder . encode ( patch ) ) ;
595- try {
596- await folderManager . repository . apply ( tempFilePath , false ) ;
597- task . report ( { message : vscode . l10n . t ( 'Successfully applied changes from pull request #{0}' , pullRequest . number . toString ( ) ) , increment : 100 } ) ;
598- } finally {
599- await vscode . workspace . fs . delete ( tempUri ) ;
600- }
601- }
602- ) ;
592+ await vscode . workspace . fs . writeFile ( tempUri , encoder . encode ( patch ) ) ;
593+ try {
594+ await folderManager . repository . apply ( tempFilePath , false ) ;
595+ task . report ( { message : vscode . l10n . t ( 'Successfully applied changes from pull request #{0}' , pullRequest . number . toString ( ) ) , increment : 100 } ) ;
596+ } finally {
597+ await vscode . workspace . fs . delete ( tempUri ) ;
598+ }
603599
604600 } catch ( error ) {
605601 const errorMessage = formatError ( error ) ;
@@ -667,21 +663,44 @@ export function registerCommands(
667663 if ( Number . isNaN ( prNumber ) ) {
668664 return vscode . window . showErrorMessage ( vscode . l10n . t ( 'Unable to parse pull request number.' ) ) ;
669665 }
670- const folderManager = reposManager . folderManagers [ 0 ] ;
671- const pullRequest = await folderManager . fetchById ( folderManager . gitHubRepositories [ 0 ] , Number ( prNumber ) ) ;
672- if ( ! pullRequest ) {
673- return vscode . window . showErrorMessage ( vscode . l10n . t ( 'Unable to find pull request #{0}' , prNumber . toString ( ) ) ) ;
674- }
675666
676- return applyPullRequestChanges ( folderManager , pullRequest ) ;
677- }
667+ await vscode . window . withProgress (
668+ {
669+ location : vscode . ProgressLocation . Notification ,
670+ title : vscode . l10n . t ( 'Applying changes from pull request #{0}' , prNumber . toString ( ) ) ,
671+ cancellable : false
672+ } ,
673+ async ( task ) => {
674+ task . report ( { increment : 30 } ) ;
678675
679- const resolved = await resolvePr ( ctx ) ;
680- if ( ! resolved ) {
681- return vscode . window . showErrorMessage ( vscode . l10n . t ( 'Unable to resolve pull request for applying changes.' ) ) ;
676+ const folderManager = reposManager . folderManagers [ 0 ] ;
677+ const pullRequest = await folderManager . fetchById ( folderManager . gitHubRepositories [ 0 ] , Number ( prNumber ) ) ;
678+ if ( ! pullRequest ) {
679+ return vscode . window . showErrorMessage ( vscode . l10n . t ( 'Unable to find pull request #{0}' , prNumber . toString ( ) ) ) ;
680+ }
681+
682+ return applyPullRequestChanges ( task , folderManager , pullRequest ) ;
683+ } ) ;
684+
685+ return ;
682686 }
683- return applyPullRequestChanges ( resolved . folderManager , resolved . pr ) ;
684687
688+ await vscode . window . withProgress (
689+ {
690+ location : vscode . ProgressLocation . Notification ,
691+ title : vscode . l10n . t ( 'Applying changes from pull request' ) ,
692+ cancellable : false
693+ } ,
694+ async ( task ) => {
695+ task . report ( { increment : 30 } ) ;
696+
697+ const resolved = await resolvePr ( ctx ) ;
698+ if ( ! resolved ) {
699+ return vscode . window . showErrorMessage ( vscode . l10n . t ( 'Unable to resolve pull request for applying changes.' ) ) ;
700+ }
701+ return applyPullRequestChanges ( task , resolved . folderManager , resolved . pr ) ;
702+ }
703+ ) ;
685704 } ) ) ;
686705
687706 context . subscriptions . push (
@@ -700,6 +719,14 @@ export function registerCommands(
700719 pullRequestModel = pr ;
701720 } else if ( isChatSessionWithPR ( pr ) ) {
702721 pullRequestModel = pr . pullRequest ;
722+ } else if ( isCrossChatSessionWithPR ( pr ) ) {
723+ const resolved = await resolvePr ( {
724+ owner : pr . pullRequestDetails . repository . owner . login ,
725+ repo : pr . pullRequestDetails . repository . name ,
726+ number : pr . pullRequestDetails . number ,
727+ preventDefaultContextMenuItems : true ,
728+ } ) ;
729+ pullRequestModel = resolved ?. pr ;
703730 } else {
704731 const resolved = await resolvePr ( pr as OverviewContext ) ;
705732 pullRequestModel = resolved ?. pr ;
@@ -963,8 +990,14 @@ export function registerCommands(
963990 await openDescription ( telemetry , issueModel , descriptionNode , folderManager , revealDescription , ! ( argument instanceof RepositoryChangesNode ) ) ;
964991 }
965992
966- async function checkoutChatSessionPullRequest ( argument : ChatSessionWithPR ) {
967- const pr = argument . pullRequest ;
993+ async function checkoutChatSessionPullRequest ( argument : ChatSessionWithPR | CrossChatSessionWithPR ) {
994+ const pr = isChatSessionWithPR ( argument ) ? argument . pullRequest : await resolvePr ( {
995+ owner : argument . pullRequestDetails . repository . owner . login ,
996+ repo : argument . pullRequestDetails . repository . name ,
997+ number : argument . pullRequestDetails . number ,
998+ preventDefaultContextMenuItems : true ,
999+ } ) . then ( resolved => resolved ?. pr ) ;
1000+
9681001 if ( ! pr ) {
9691002 Logger . warn ( `No pull request found in chat session` , logId ) ;
9701003 return ;
@@ -979,18 +1012,28 @@ export function registerCommands(
9791012 return switchToPr ( folderManager , pr , folderManager . repository , false ) ;
9801013 }
9811014
982- async function closeChatSessionPullRequest ( argument : ChatSessionWithPR ) {
983- const pr = argument . pullRequest ;
1015+ async function closeChatSessionPullRequest ( argument : ChatSessionWithPR | CrossChatSessionWithPR ) {
1016+ const pr = isChatSessionWithPR ( argument ) ? argument . pullRequest : await resolvePr ( {
1017+ owner : argument . pullRequestDetails . repository . owner . login ,
1018+ repo : argument . pullRequestDetails . repository . name ,
1019+ number : argument . pullRequestDetails . number ,
1020+ preventDefaultContextMenuItems : true ,
1021+ } ) . then ( resolved => resolved ?. pr ) ;
9841022 if ( ! pr ) {
9851023 Logger . warn ( `No pull request found in chat session` , logId ) ;
9861024 return ;
9871025 }
988- pr . close ( ) ;
1026+ await pr . close ( ) ;
9891027 copilotRemoteAgentManager . refreshChatSessions ( ) ;
9901028 }
9911029
992- async function cancelCodingAgent ( argument : ChatSessionWithPR ) {
993- const pr = argument . pullRequest ;
1030+ async function cancelCodingAgent ( argument : ChatSessionWithPR | CrossChatSessionWithPR ) {
1031+ const pr = isChatSessionWithPR ( argument ) ? argument . pullRequest : await resolvePr ( {
1032+ owner : argument . pullRequestDetails . repository . owner . login ,
1033+ repo : argument . pullRequestDetails . repository . name ,
1034+ number : argument . pullRequestDetails . number ,
1035+ preventDefaultContextMenuItems : true ,
1036+ } ) . then ( resolved => resolved ?. pr ) ;
9941037 if ( ! pr ) {
9951038 Logger . warn ( `No pull request found in chat session` , logId ) ;
9961039 return ;
0 commit comments