@@ -606,75 +606,84 @@ export function registerCommands(
606606 }
607607 }
608608
609- context . subscriptions . push ( vscode . commands . registerCommand ( 'pr.checkoutFromDescription' , async ( ctx : OverviewContext | { path : string } | undefined , metadata ?: SessionMetadata ) => {
609+ type ChatCommandArgs = { path : string } | [ { path : string } | undefined , SessionMetadata | undefined ] | undefined ;
610+
611+ function parseChatCommandArgs ( ctxOrArgs : ChatCommandArgs , metadataArg ?: SessionMetadata ) : { ctx : { path : string } | undefined ; metadata : SessionMetadata | undefined } {
612+ if ( Array . isArray ( ctxOrArgs ) ) {
613+ return { ctx : ctxOrArgs [ 0 ] , metadata : ctxOrArgs [ 1 ] } ;
614+ }
615+ return { ctx : ctxOrArgs , metadata : metadataArg } ;
616+ }
617+
618+ async function resolvePrFromChat ( ctx : { path : string } , metadata : SessionMetadata | undefined ) : Promise < { folderManager : FolderRepositoryManager ; pullRequest : PullRequestModel ; prNumber : number } | undefined > {
619+ const prNumber = prNumberFromUriPath ( ctx . path ) ;
620+ if ( ! prNumber ) {
621+ return undefined ;
622+ }
623+ const result = getFolderManagerFromMetadata ( metadata ) ;
624+ if ( ! result ) {
625+ return undefined ;
626+ }
627+ const { folderManager, githubRepo } = result ;
628+ const pullRequest = await folderManager . fetchById ( githubRepo , prNumber ) ;
629+ if ( ! pullRequest ) {
630+ return undefined ;
631+ }
632+ return { folderManager, pullRequest, prNumber } ;
633+ }
634+
635+ context . subscriptions . push ( vscode . commands . registerCommand ( 'pr.checkoutFromChat' , async ( ctxOrArgs : ChatCommandArgs , metadataArg ?: SessionMetadata ) => {
636+ const { ctx, metadata } = parseChatCommandArgs ( ctxOrArgs , metadataArg ) ;
610637 if ( ! ctx ) {
611638 return vscode . window . showErrorMessage ( vscode . l10n . t ( 'No pull request context provided for checkout.' ) ) ;
612639 }
613640
614- if ( contextHasPath ( ctx ) ) {
615- const { path } = ctx ;
616- const prNumber = prNumberFromUriPath ( path ) ;
617- if ( ! prNumber ) {
618- return vscode . window . showErrorMessage ( vscode . l10n . t ( 'No pull request number found in context path.' ) ) ;
619- }
620- // Use metadata to find the correct repository if available
621- const result = getFolderManagerFromMetadata ( metadata ) ;
622- if ( ! result ) {
623- return vscode . window . showErrorMessage ( vscode . l10n . t ( 'Unable to find repository manager.' ) ) ;
624- }
625- const { folderManager, githubRepo } = result ;
626- const pullRequest = await folderManager . fetchById ( githubRepo , Number ( prNumber ) ) ;
627- if ( ! pullRequest ) {
628- return vscode . window . showErrorMessage ( vscode . l10n . t ( 'Unable to find pull request #{0}' , prNumber . toString ( ) ) ) ;
629- }
641+ const resolved = await resolvePrFromChat ( ctx , metadata ) ;
642+ if ( ! resolved ) {
643+ return vscode . window . showErrorMessage ( vscode . l10n . t ( 'Unable to find pull request from chat context.' ) ) ;
644+ }
630645
631- return reviewsManager . switchToPr ( folderManager , pullRequest , folderManager . repository , true ) ;
646+ return reviewsManager . switchToPr ( resolved . folderManager , resolved . pullRequest , resolved . folderManager . repository , true ) ;
647+ } ) ) ;
648+
649+ context . subscriptions . push ( vscode . commands . registerCommand ( 'pr.checkoutFromDescription' , async ( ctx : OverviewContext | undefined ) => {
650+ if ( ! ctx ) {
651+ return vscode . window . showErrorMessage ( vscode . l10n . t ( 'No pull request context provided for checkout.' ) ) ;
632652 }
633653
634654 const resolved = await resolvePr ( ctx ) ;
635655 if ( ! resolved ) {
636656 return vscode . window . showErrorMessage ( vscode . l10n . t ( 'Unable to resolve pull request for checkout.' ) ) ;
637657 }
638658 return reviewsManager . switchToPr ( resolved . folderManager , resolved . pr , resolved . folderManager . repository , true ) ;
639-
640659 } ) ) ;
641660
642- context . subscriptions . push ( vscode . commands . registerCommand ( 'pr.applyChangesFromDescription' , async ( ctx : OverviewContext | { path : string } | undefined , metadata ?: SessionMetadata ) => {
661+ context . subscriptions . push ( vscode . commands . registerCommand ( 'pr.applyChangesFromChat' , async ( ctxOrArgs : ChatCommandArgs , metadataArg ?: SessionMetadata ) => {
662+ const { ctx, metadata } = parseChatCommandArgs ( ctxOrArgs , metadataArg ) ;
643663 if ( ! ctx ) {
644664 return vscode . window . showErrorMessage ( vscode . l10n . t ( 'No pull request context provided for applying changes.' ) ) ;
645665 }
646666
647- if ( contextHasPath ( ctx ) ) {
648- const { path } = ctx ;
649- const prNumber = prNumberFromUriPath ( path ) ;
650- if ( ! prNumber ) {
651- return vscode . window . showErrorMessage ( vscode . l10n . t ( 'Unable to parse pull request number.' ) ) ;
652- }
653-
654- await vscode . window . withProgress (
655- {
656- location : vscode . ProgressLocation . Notification ,
657- title : vscode . l10n . t ( 'Applying changes from pull request #{0}' , prNumber . toString ( ) ) ,
658- cancellable : false
659- } ,
660- async ( task ) => {
661- task . report ( { increment : 30 } ) ;
662-
663- // Use metadata to find the correct repository if available
664- const result = getFolderManagerFromMetadata ( metadata ) ;
665- if ( ! result ) {
666- return vscode . window . showErrorMessage ( vscode . l10n . t ( 'Unable to find repository manager.' ) ) ;
667- }
668- const { folderManager, githubRepo } = result ;
669- const pullRequest = await folderManager . fetchById ( githubRepo , Number ( prNumber ) ) ;
670- if ( ! pullRequest ) {
671- return vscode . window . showErrorMessage ( vscode . l10n . t ( 'Unable to find pull request #{0}' , prNumber . toString ( ) ) ) ;
672- }
667+ const resolved = await resolvePrFromChat ( ctx , metadata ) ;
668+ if ( ! resolved ) {
669+ return vscode . window . showErrorMessage ( vscode . l10n . t ( 'Unable to find pull request from chat context.' ) ) ;
670+ }
673671
674- return applyPullRequestChanges ( task , folderManager , pullRequest ) ;
675- } ) ;
672+ await vscode . window . withProgress (
673+ {
674+ location : vscode . ProgressLocation . Notification ,
675+ title : vscode . l10n . t ( 'Applying changes from pull request #{0}' , resolved . prNumber . toString ( ) ) ,
676+ cancellable : false
677+ } ,
678+ async ( task ) => {
679+ task . report ( { increment : 30 } ) ;
680+ return applyPullRequestChanges ( task , resolved . folderManager , resolved . pullRequest ) ;
681+ } ) ;
682+ } ) ) ;
676683
677- return ;
684+ context . subscriptions . push ( vscode . commands . registerCommand ( 'pr.applyChangesFromDescription' , async ( ctx : OverviewContext | undefined ) => {
685+ if ( ! ctx ) {
686+ return vscode . window . showErrorMessage ( vscode . l10n . t ( 'No pull request context provided for applying changes.' ) ) ;
678687 }
679688
680689 await vscode . window . withProgress (
0 commit comments