@@ -13,6 +13,7 @@ import { FolderRepositoryManager } from './folderRepositoryManager';
13
13
import { GithubItemStateEnum , MergeMethod , ReviewEvent , ReviewState } from './interface' ;
14
14
import { PullRequestModel } from './pullRequestModel' ;
15
15
import { getDefaultMergeMethod } from './pullRequestOverview' ;
16
+ import { PullRequestView } from './pullRequestOverviewCommon' ;
16
17
import { isInCodespaces , parseReviewers } from './utils' ;
17
18
18
19
export class PullRequestViewProvider extends WebviewViewBase implements vscode . WebviewViewProvider {
@@ -292,123 +293,11 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
292
293
}
293
294
294
295
private async deleteBranch ( message : IRequestMessage < any > ) {
295
- const branchInfo = await this . _folderRepositoryManager . getBranchNameForPullRequest ( this . _item ) ;
296
- const actions : ( vscode . QuickPickItem & { type : 'upstream' | 'local' | 'remote' | 'suspend' } ) [ ] = [ ] ;
297
-
298
- if ( this . _item . isResolved ( ) ) {
299
- const branchHeadRef = this . _item . head . ref ;
300
-
301
- const defaultBranch = await this . _folderRepositoryManager . getPullRequestRepositoryDefaultBranch ( this . _item ) ;
302
- const isDefaultBranch = defaultBranch === this . _item . head . ref ;
303
- if ( ! isDefaultBranch ) {
304
- actions . push ( {
305
- label : `Delete remote branch ${ this . _item . remote . remoteName } /${ branchHeadRef } ` ,
306
- description : `${ this . _item . remote . normalizedHost } /${ this . _item . remote . owner } /${ this . _item . remote . repositoryName } ` ,
307
- type : 'upstream' ,
308
- picked : true ,
309
- } ) ;
310
- }
311
- }
312
-
313
- if ( branchInfo ) {
314
- const preferredLocalBranchDeletionMethod = vscode . workspace
315
- . getConfiguration ( 'githubPullRequests' )
316
- . get < boolean > ( 'defaultDeletionMethod.selectLocalBranch' ) ;
317
- actions . push ( {
318
- label : `Delete local branch ${ branchInfo . branch } ` ,
319
- type : 'local' ,
320
- picked : ! ! preferredLocalBranchDeletionMethod ,
321
- } ) ;
322
-
323
- const preferredRemoteDeletionMethod = vscode . workspace
324
- . getConfiguration ( 'githubPullRequests' )
325
- . get < boolean > ( 'defaultDeletionMethod.selectRemote' ) ;
326
-
327
- if ( branchInfo . remote && branchInfo . createdForPullRequest && ! branchInfo . remoteInUse ) {
328
- actions . push ( {
329
- label : `Delete remote ${ branchInfo . remote } , which is no longer used by any other branch` ,
330
- type : 'remote' ,
331
- picked : ! ! preferredRemoteDeletionMethod ,
332
- } ) ;
333
- }
334
- }
335
-
336
- if ( vscode . env . remoteName === 'codespaces' ) {
337
- actions . push ( {
338
- label : 'Suspend Codespace' ,
339
- type : 'suspend'
340
- } ) ;
341
- }
342
-
343
- if ( ! actions . length ) {
344
- vscode . window . showWarningMessage (
345
- `There is no longer an upstream or local branch for Pull Request #${ this . _item . number } ` ,
346
- ) ;
347
- this . _replyMessage ( message , {
348
- cancelled : true ,
349
- } ) ;
350
-
351
- return ;
352
- }
353
-
354
- const selectedActions = await vscode . window . showQuickPick ( actions , {
355
- canPickMany : true ,
356
- ignoreFocusOut : true ,
357
- } ) ;
358
-
359
- const deletedBranchTypes : string [ ] = [ ] ;
360
-
361
- if ( selectedActions ) {
362
- const isBranchActive = this . _item . equals ( this . _folderRepositoryManager . activePullRequest ) ;
363
-
364
- const promises = selectedActions . map ( async action => {
365
- switch ( action . type ) {
366
- case 'upstream' :
367
- await this . _folderRepositoryManager . deleteBranch ( this . _item ) ;
368
- deletedBranchTypes . push ( action . type ) ;
369
- return this . _folderRepositoryManager . repository . fetch ( { prune : true } ) ;
370
- case 'local' :
371
- if ( isBranchActive ) {
372
- if ( this . _folderRepositoryManager . repository . state . workingTreeChanges . length ) {
373
- const response = await vscode . window . showWarningMessage (
374
- `Your local changes will be lost, do you want to continue?` ,
375
- { modal : true } ,
376
- 'Yes' ,
377
- ) ;
378
- if ( response === 'Yes' ) {
379
- await vscode . commands . executeCommand ( 'git.cleanAll' ) ;
380
- } else {
381
- return ;
382
- }
383
- }
384
- const defaultBranch = await this . _folderRepositoryManager . getPullRequestRepositoryDefaultBranch (
385
- this . _item ,
386
- ) ;
387
- await this . _folderRepositoryManager . repository . checkout ( defaultBranch ) ;
388
- }
389
- await this . _folderRepositoryManager . repository . deleteBranch ( branchInfo ! . branch , true ) ;
390
- return deletedBranchTypes . push ( action . type ) ;
391
- case 'remote' :
392
- await this . _folderRepositoryManager . repository . removeRemote ( branchInfo ! . remote ! ) ;
393
- return deletedBranchTypes . push ( action . type ) ;
394
- case 'suspend' :
395
- await vscode . commands . executeCommand ( 'github.codespaces.disconnectSuspend' ) ;
396
- return deletedBranchTypes . push ( action . type ) ;
397
- }
398
- } ) ;
399
-
400
- await Promise . all ( promises ) ;
401
-
402
- vscode . commands . executeCommand ( 'pr.refreshList' ) ;
403
-
404
- this . _postMessage ( {
405
- command : 'pr.deleteBranch' ,
406
- branchTypes : deletedBranchTypes
407
- } ) ;
296
+ const result = await PullRequestView . deleteBranch ( this . _folderRepositoryManager , this . _item ) ;
297
+ if ( result . isReply ) {
298
+ this . _replyMessage ( message , result . message ) ;
408
299
} else {
409
- this . _replyMessage ( message , {
410
- cancelled : true ,
411
- } ) ;
300
+ this . _postMessage ( result . message ) ;
412
301
}
413
302
}
414
303
0 commit comments