@@ -26,7 +26,7 @@ import { isCopilotOnMyBehalf, PullRequestModel } from './pullRequestModel';
2626import { PullRequestReviewCommon , ReviewContext } from './pullRequestReviewCommon' ;
2727import { branchPicks , pickEmail , reviewersQuickPick } from './quickPicks' ;
2828import { parseReviewers } from './utils' ;
29- import { CancelCodingAgentReply , ChangeBaseReply , ChangeReviewersReply , DeleteReviewResult , MergeArguments , MergeResult , PullRequest , ReviewType , UnresolvedIdentity } from './views' ;
29+ import { CancelCodingAgentReply , ChangeBaseReply , ChangeReviewersReply , DeleteReviewResult , MergeArguments , MergeResult , PullRequest , ReadyForReviewAndMergeContext , ReadyForReviewContext , ReviewCommentContext , ReviewType , UnresolvedIdentity } from './views' ;
3030import { debounce } from '../common/async' ;
3131import { COPILOT_ACCOUNTS , IComment } from '../common/comment' ;
3232import { COPILOT_REVIEWER , COPILOT_REVIEWER_ACCOUNT , COPILOT_SWE_AGENT , copilotEventToStatus , CopilotPRStatus , mostRecentCopilotEvent } from '../common/copilot' ;
@@ -127,6 +127,75 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
127127 return this . currentPanel ?. _item ;
128128 }
129129
130+ /**
131+ * Find the panel showing a specific pull request.
132+ * Currently there is at most one panel, but this will support
133+ * multiple panels in the future.
134+ */
135+ public static findPanel ( owner : string , repo : string , number : number ) : PullRequestOverviewPanel | undefined {
136+ const panel = this . currentPanel ;
137+ if ( panel && panel . _item &&
138+ panel . _item . remote . owner === owner &&
139+ panel . _item . remote . repositoryName === repo &&
140+ panel . _item . number === number ) {
141+ return panel ;
142+ }
143+ return undefined ;
144+ }
145+
146+ /**
147+ * Register the webview context-menu commands once globally,
148+ * rather than per panel instance. Each command receives the
149+ * PR identity (owner / repo / number) from the webview context
150+ * and looks up the matching panel.
151+ */
152+ public static registerGlobalCommands ( context : vscode . ExtensionContext , telemetry : ITelemetry ) : void {
153+ context . subscriptions . push (
154+ vscode . commands . registerCommand ( 'pr.readyForReviewDescription' , async ( ctx : ReadyForReviewContext ) => {
155+ const panel = PullRequestOverviewPanel . findPanel ( ctx . owner , ctx . repo , ctx . number ) ;
156+ if ( panel ) {
157+ return panel . readyForReviewCommand ( ) ;
158+ }
159+ } ) ,
160+ vscode . commands . registerCommand ( 'pr.readyForReviewAndMergeDescription' , async ( ctx : ReadyForReviewAndMergeContext ) => {
161+ const panel = PullRequestOverviewPanel . findPanel ( ctx . owner , ctx . repo , ctx . number ) ;
162+ if ( panel ) {
163+ return panel . readyForReviewAndMergeCommand ( ctx ) ;
164+ }
165+ } ) ,
166+ vscode . commands . registerCommand ( 'review.approveDescription' , ( ctx : ReviewCommentContext ) => {
167+ const panel = PullRequestOverviewPanel . findPanel ( ctx . owner , ctx . repo , ctx . number ) ;
168+ if ( panel ) {
169+ return panel . approvePullRequestCommand ( ctx ) ;
170+ }
171+ } ) ,
172+ vscode . commands . registerCommand ( 'review.commentDescription' , ( ctx : ReviewCommentContext ) => {
173+ const panel = PullRequestOverviewPanel . findPanel ( ctx . owner , ctx . repo , ctx . number ) ;
174+ if ( panel ) {
175+ return panel . submitReviewCommand ( ctx ) ;
176+ }
177+ } ) ,
178+ vscode . commands . registerCommand ( 'review.requestChangesDescription' , ( ctx : ReviewCommentContext ) => {
179+ const panel = PullRequestOverviewPanel . findPanel ( ctx . owner , ctx . repo , ctx . number ) ;
180+ if ( panel ) {
181+ return panel . requestChangesCommand ( ctx ) ;
182+ }
183+ } ) ,
184+ vscode . commands . registerCommand ( 'review.approveOnDotComDescription' , ( ctx : ReviewCommentContext ) => {
185+ const panel = PullRequestOverviewPanel . findPanel ( ctx . owner , ctx . repo , ctx . number ) ;
186+ if ( panel ) {
187+ return openPullRequestOnGitHub ( panel . _item , telemetry ) ;
188+ }
189+ } ) ,
190+ vscode . commands . registerCommand ( 'review.requestChangesOnDotComDescription' , ( ctx : ReviewCommentContext ) => {
191+ const panel = PullRequestOverviewPanel . findPanel ( ctx . owner , ctx . repo , ctx . number ) ;
192+ if ( panel ) {
193+ return openPullRequestOnGitHub ( panel . _item , telemetry ) ;
194+ }
195+ } ) ,
196+ ) ;
197+ }
198+
130199 protected constructor (
131200 telemetry : ITelemetry ,
132201 extensionUri : vscode . Uri ,
@@ -143,22 +212,6 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
143212 this . registerPrListeners ( ) ;
144213
145214 this . setVisibilityContext ( ) ;
146-
147- this . _register ( vscode . commands . registerCommand ( 'pr.readyForReviewDescription' , async ( ) => {
148- return this . readyForReviewCommand ( ) ;
149- } ) ) ;
150- this . _register ( vscode . commands . registerCommand ( 'pr.readyForReviewAndMergeDescription' , async ( context : { mergeMethod : MergeMethod } ) => {
151- return this . readyForReviewAndMergeCommand ( context ) ;
152- } ) ) ;
153- this . _register ( vscode . commands . registerCommand ( 'review.approveDescription' , ( e ) => this . approvePullRequestCommand ( e ) ) ) ;
154- this . _register ( vscode . commands . registerCommand ( 'review.commentDescription' , ( e ) => this . submitReviewCommand ( e ) ) ) ;
155- this . _register ( vscode . commands . registerCommand ( 'review.requestChangesDescription' , ( e ) => this . requestChangesCommand ( e ) ) ) ;
156- this . _register ( vscode . commands . registerCommand ( 'review.approveOnDotComDescription' , ( ) => {
157- return openPullRequestOnGitHub ( this . _item , this . _telemetry ) ;
158- } ) ) ;
159- this . _register ( vscode . commands . registerCommand ( 'review.requestChangesOnDotComDescription' , ( ) => {
160- return openPullRequestOnGitHub ( this . _item , this . _telemetry ) ;
161- } ) ) ;
162215 }
163216
164217 protected override registerPrListeners ( ) {
0 commit comments