FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
vscode-pull-request-github/src/github/pullRequestOverview.ts at main · ANT0071/vscode-pull-request-github · GitHub
ANT0071
/
vscode-pull-request-github
Public
forked from
microsoft/vscode-pull-request-github
Notifications
You must be signed in to change notification settings
Fork
1
Star
1
Code
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
vscode-pull-request-github
/
src
/
github
/
pullRequestOverview.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
890 lines (796 loc) · 33.3 KB
Breadcrumbs
vscode-pull-request-github
/
src
/
github
/
pullRequestOverview.ts
Copy path
File metadata and controls
890 lines (796 loc) · 33.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict'
;
import
*
as
vscode
from
'vscode'
;
import
{
OpenCommitChangesArgs
}
from
'../../common/views'
;
import
{
openPullRequestOnGitHub
}
from
'../commands'
;
import
{
IComment
}
from
'../common/comment'
;
import
{
COPILOT_LOGINS
,
copilotEventToStatus
,
CopilotPRStatus
,
mostRecentCopilotEvent
}
from
'../common/copilot'
;
import
{
commands
,
contexts
}
from
'../common/executeCommands'
;
import
{
disposeAll
}
from
'../common/lifecycle'
;
import
Logger
from
'../common/logger'
;
import
{
DEFAULT_MERGE_METHOD
,
PR_SETTINGS_NAMESPACE
}
from
'../common/settingKeys'
;
import
{
ITelemetry
}
from
'../common/telemetry'
;
import
{
EventType
,
ReviewEvent
,
SessionLinkInfo
,
TimelineEvent
}
from
'../common/timelineEvent'
;
import
{
asPromise
,
formatError
}
from
'../common/utils'
;
import
{
IRequestMessage
,
PULL_REQUEST_OVERVIEW_VIEW_TYPE
}
from
'../common/webview'
;
import
{
SessionLogViewManager
}
from
'../view/sessionLogView'
;
import
{
getCopilotApi
}
from
'./copilotApi'
;
import
{
FolderRepositoryManager
}
from
'./folderRepositoryManager'
;
import
{
GithubItemStateEnum
,
IAccount
,
isITeam
,
ITeam
,
MergeMethod
,
MergeMethodsAvailability
,
PullRequestMergeability
,
reviewerId
,
ReviewEventEnum
,
ReviewState
,
}
from
'./interface'
;
import
{
IssueOverviewPanel
}
from
'./issueOverview'
;
import
{
isCopilotOnMyBehalf
,
PullRequestModel
}
from
'./pullRequestModel'
;
import
{
PullRequestView
}
from
'./pullRequestOverviewCommon'
;
import
{
pickEmail
,
reviewersQuickPick
}
from
'./quickPicks'
;
import
{
parseReviewers
}
from
'./utils'
;
import
{
CancelCodingAgentReply
,
MergeArguments
,
MergeResult
,
PullRequest
,
ReviewType
,
SubmitReviewReply
}
from
'./views'
;
export
class
PullRequestOverviewPanel
extends
IssueOverviewPanel
<
PullRequestModel
>
{
public
static
override
ID
:
string
=
'PullRequestOverviewPanel'
;
public
static
override
readonly
viewType
=
PULL_REQUEST_OVERVIEW_VIEW_TYPE
;
/**
* Track the currently panel. Only allow a single panel to exist at a time.
*/
public
static
override
currentPanel
?:
PullRequestOverviewPanel
;
/**
* Event emitter for when a PR overview becomes active
*/
private
static
_onVisible
=
new
vscode
.
EventEmitter
<
PullRequestModel
>
(
)
;
public
static
readonly
onVisible
=
PullRequestOverviewPanel
.
_onVisible
.
event
;
private
_repositoryDefaultBranch
:
string
;
private
_existingReviewers
:
ReviewState
[
]
=
[
]
;
private
_teamsCount
=
0
;
private
_prListeners
:
vscode
.
Disposable
[
]
=
[
]
;
private
_isUpdating
:
boolean
=
false
;
public
static
override
async
createOrShow
(
telemetry
:
ITelemetry
,
extensionUri
:
vscode
.
Uri
,
folderRepositoryManager
:
FolderRepositoryManager
,
issue
:
PullRequestModel
,
toTheSide
:
boolean
=
false
,
preserveFocus
:
boolean
=
true
,
existingPanel
?:
vscode
.
WebviewPanel
)
{
/* __GDPR__
"pr.openDescription" : {
"isCopilot" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
telemetry
.
sendTelemetryEvent
(
'pr.openDescription'
,
{
isCopilot
:
(
issue
.
author
.
login
===
COPILOT_LOGINS
[
1
]
)
?
'true'
:
'false'
}
)
;
const
activeColumn
=
toTheSide
?
vscode
.
ViewColumn
.
Beside
:
vscode
.
window
.
activeTextEditor
?
vscode
.
window
.
activeTextEditor
.
viewColumn
:
vscode
.
ViewColumn
.
One
;
// If we already have a panel, show it.
// Otherwise, create a new panel.
if
(
PullRequestOverviewPanel
.
currentPanel
)
{
PullRequestOverviewPanel
.
currentPanel
.
_panel
.
reveal
(
activeColumn
,
preserveFocus
)
;
}
else
{
const
title
=
`Pull Request #
${
issue
.
number
.
toString
(
)
}
`
;
PullRequestOverviewPanel
.
currentPanel
=
new
PullRequestOverviewPanel
(
telemetry
,
extensionUri
,
activeColumn
||
vscode
.
ViewColumn
.
Active
,
title
,
folderRepositoryManager
,
existingPanel
)
;
}
await
PullRequestOverviewPanel
.
currentPanel
!
.
update
(
folderRepositoryManager
,
issue
)
;
}
protected
override
set
_currentPanel
(
panel
:
PullRequestOverviewPanel
|
undefined
)
{
PullRequestOverviewPanel
.
currentPanel
=
panel
;
}
public
static
override
refresh
(
)
:
void
{
if
(
this
.
currentPanel
)
{
this
.
currentPanel
.
refreshPanel
(
)
;
}
}
public
static
scrollToReview
(
)
:
void
{
if
(
this
.
currentPanel
)
{
this
.
currentPanel
.
_postMessage
(
{
command
:
'pr.scrollToPendingReview'
}
)
;
}
}
/**
* Get the currently active pull request from the current panel
*/
public
static
getCurrentPullRequest
(
)
:
PullRequestModel
|
undefined
{
return
this
.
currentPanel
?.
_item
;
}
protected
constructor
(
telemetry
:
ITelemetry
,
extensionUri
:
vscode
.
Uri
,
column
:
vscode
.
ViewColumn
,
title
:
string
,
folderRepositoryManager
:
FolderRepositoryManager
,
existingPanel
?:
vscode
.
WebviewPanel
)
{
super
(
telemetry
,
extensionUri
,
column
,
title
,
folderRepositoryManager
,
PullRequestOverviewPanel
.
viewType
,
existingPanel
,
{
light
:
'resources/icons/pr_webview.svg'
,
dark
:
'resources/icons/dark/pr_webview.svg'
}
)
;
this
.
registerPrListeners
(
)
;
this
.
setVisibilityContext
(
)
;
this
.
_register
(
folderRepositoryManager
.
onDidMergePullRequest
(
_
=>
{
this
.
_postMessage
(
{
command
:
'update-state'
,
state
:
GithubItemStateEnum
.
Merged
,
}
)
;
}
)
)
;
this
.
_register
(
vscode
.
commands
.
registerCommand
(
'review.approveDescription'
,
(
e
)
=>
this
.
approvePullRequestCommand
(
e
)
)
)
;
this
.
_register
(
vscode
.
commands
.
registerCommand
(
'review.commentDescription'
,
(
e
)
=>
this
.
submitReviewCommand
(
e
)
)
)
;
this
.
_register
(
vscode
.
commands
.
registerCommand
(
'review.requestChangesDescription'
,
(
e
)
=>
this
.
requestChangesCommand
(
e
)
)
)
;
this
.
_register
(
vscode
.
commands
.
registerCommand
(
'review.approveOnDotComDescription'
,
(
)
=>
{
return
openPullRequestOnGitHub
(
this
.
_item
,
(
this
.
_item
as
any
)
.
_telemetry
)
;
}
)
)
;
this
.
_register
(
vscode
.
commands
.
registerCommand
(
'review.requestChangesOnDotComDescription'
,
(
)
=>
{
return
openPullRequestOnGitHub
(
this
.
_item
,
(
this
.
_item
as
any
)
.
_telemetry
)
;
}
)
)
;
}
protected
override
registerPrListeners
(
)
{
disposeAll
(
this
.
_prListeners
)
;
this
.
_prListeners
.
push
(
this
.
_folderRepositoryManager
.
onDidChangeActivePullRequest
(
_
=>
{
if
(
this
.
_folderRepositoryManager
&&
this
.
_item
)
{
const
isCurrentlyCheckedOut
=
this
.
_item
.
equals
(
this
.
_folderRepositoryManager
.
activePullRequest
)
;
this
.
_postMessage
(
{
command
:
'pr.update-checkout-status'
,
isCurrentlyCheckedOut
,
}
)
;
}
}
)
)
;
if
(
this
.
_item
)
{
this
.
_prListeners
.
push
(
this
.
_item
.
onDidChange
(
e
=>
{
if
(
e
.
comments
&&
!
this
.
_isUpdating
)
{
this
.
refreshPanel
(
)
;
}
}
)
)
;
}
}
protected
override
onDidChangeViewState
(
e
:
vscode
.
WebviewPanelOnDidChangeViewStateEvent
)
:
void
{
super
.
onDidChangeViewState
(
e
)
;
this
.
setVisibilityContext
(
)
;
// If the panel becomes visible and we have an item, notify that this PR is active
if
(
this
.
_panel
.
visible
&&
this
.
_item
)
{
PullRequestOverviewPanel
.
_onVisible
.
fire
(
this
.
_item
)
;
}
}
private
setVisibilityContext
(
)
{
return
commands
.
setContext
(
contexts
.
PULL_REQUEST_DESCRIPTION_VISIBLE
,
this
.
_panel
.
visible
)
;
}
/**
* Find currently configured user's review status for the current PR
*
@param
reviewers All the reviewers who have been requested to review the current PR
*
@param
pullRequestModel Model of the PR
*/
private
getCurrentUserReviewState
(
reviewers
:
ReviewState
[
]
,
currentUser
:
IAccount
)
:
string
|
undefined
{
const
review
=
reviewers
.
find
(
r
=>
reviewerId
(
r
.
reviewer
)
===
currentUser
.
login
)
;
// There will always be a review. If not then the PR shouldn't have been or fetched/shown for the current user
return
review
?.
state
;
}
private
isUpdateBranchWithGitHubEnabled
(
)
:
boolean
{
return
this
.
_item
.
isActive
||
vscode
.
workspace
.
getConfiguration
(
PR_SETTINGS_NAMESPACE
)
.
get
(
'experimentalUpdateBranchWithGitHub'
,
false
)
;
}
protected
override
continueOnGitHub
(
)
{
const
isCrossRepository
:
boolean
=
!
!
this
.
_item
.
base
&&
!
!
this
.
_item
.
head
&&
!
this
.
_item
.
base
.
repositoryCloneUrl
.
equals
(
this
.
_item
.
head
.
repositoryCloneUrl
)
;
return
super
.
continueOnGitHub
(
)
&&
isCrossRepository
;
}
private
preLoadInfoNotRequiredForOverview
(
pullRequest
:
PullRequestModel
)
:
void
{
// Load some more info in the background, don't await.
pullRequest
.
getFileChangesInfo
(
)
;
}
protected
override
async
updateItem
(
pullRequestModel
:
PullRequestModel
)
:
Promise
<
void
>
{
try
{
const
[
pullRequest
,
timelineEvents
,
defaultBranch
,
status
,
requestedReviewers
,
repositoryAccess
,
branchInfo
,
currentUser
,
viewerCanEdit
,
orgTeamsCount
,
mergeQueueMethod
,
isBranchUpToDateWithBase
,
mergeability
,
emailForCommit
,
coAuthors
,
hasReviewDraft
]
=
await
Promise
.
all
(
[
this
.
_folderRepositoryManager
.
resolvePullRequest
(
pullRequestModel
.
remote
.
owner
,
pullRequestModel
.
remote
.
repositoryName
,
pullRequestModel
.
number
,
)
,
pullRequestModel
.
getTimelineEvents
(
pullRequestModel
)
,
this
.
_folderRepositoryManager
.
getPullRequestRepositoryDefaultBranch
(
pullRequestModel
)
,
pullRequestModel
.
getStatusChecks
(
)
,
pullRequestModel
.
getReviewRequests
(
)
,
this
.
_folderRepositoryManager
.
getPullRequestRepositoryAccessAndMergeMethods
(
pullRequestModel
)
,
this
.
_folderRepositoryManager
.
getBranchNameForPullRequest
(
pullRequestModel
)
,
this
.
_folderRepositoryManager
.
getCurrentUser
(
pullRequestModel
.
githubRepository
)
,
pullRequestModel
.
canEdit
(
)
,
this
.
_folderRepositoryManager
.
getOrgTeamsCount
(
pullRequestModel
.
githubRepository
)
,
this
.
_folderRepositoryManager
.
mergeQueueMethodForBranch
(
pullRequestModel
.
base
.
ref
,
pullRequestModel
.
remote
.
owner
,
pullRequestModel
.
remote
.
repositoryName
)
,
this
.
_folderRepositoryManager
.
isHeadUpToDateWithBase
(
pullRequestModel
)
,
pullRequestModel
.
getMergeability
(
)
,
this
.
_folderRepositoryManager
.
getPreferredEmail
(
pullRequestModel
)
,
pullRequestModel
.
getCoAuthors
(
)
,
pullRequestModel
.
validateDraftMode
(
)
,
]
)
;
if
(
!
pullRequest
)
{
throw
new
Error
(
`Fail to resolve Pull Request #
${
pullRequestModel
.
number
}
in
${
pullRequestModel
.
remote
.
owner
}
/
${
pullRequestModel
.
remote
.
repositoryName
}
`
,
)
;
}
this
.
_item
=
pullRequest
;
this
.
registerPrListeners
(
)
;
this
.
_repositoryDefaultBranch
=
defaultBranch
!
;
this
.
_teamsCount
=
orgTeamsCount
;
this
.
setPanelTitle
(
`Pull Request #
${
pullRequestModel
.
number
.
toString
(
)
}
`
)
;
const
isCurrentlyCheckedOut
=
pullRequestModel
.
equals
(
this
.
_folderRepositoryManager
.
activePullRequest
)
;
const
mergeMethodsAvailability
=
repositoryAccess
!
.
mergeMethodsAvailability
;
const
defaultMergeMethod
=
getDefaultMergeMethod
(
mergeMethodsAvailability
)
;
this
.
_existingReviewers
=
parseReviewers
(
requestedReviewers
!
,
timelineEvents
!
,
pullRequest
.
author
)
;
const
isUpdateBranchWithGitHubEnabled
:
boolean
=
this
.
isUpdateBranchWithGitHubEnabled
(
)
;
const
reviewState
=
this
.
getCurrentUserReviewState
(
this
.
_existingReviewers
,
currentUser
)
;
Logger
.
debug
(
'pr.initialize'
,
PullRequestOverviewPanel
.
ID
)
;
const
baseContext
=
this
.
getInitializeContext
(
currentUser
,
pullRequest
,
timelineEvents
,
repositoryAccess
,
viewerCanEdit
,
[
]
)
;
this
.
preLoadInfoNotRequiredForOverview
(
pullRequest
)
;
const
context
:
Partial
<
PullRequest
>
=
{
...
baseContext
,
isCurrentlyCheckedOut
:
isCurrentlyCheckedOut
,
isRemoteBaseDeleted
:
pullRequest
.
isRemoteBaseDeleted
,
base
:
pullRequest
.
base
.
label
,
isRemoteHeadDeleted
:
pullRequest
.
isRemoteHeadDeleted
,
isLocalHeadDeleted
:
!
branchInfo
,
head
:
pullRequest
.
head
?.
label
??
''
,
repositoryDefaultBranch
:
defaultBranch
,
status
:
status
[
0
]
,
reviewRequirement
:
status
[
1
]
,
canUpdateBranch
:
pullRequest
.
item
.
viewerCanUpdate
&&
!
isBranchUpToDateWithBase
&&
isUpdateBranchWithGitHubEnabled
,
mergeable
:
mergeability
.
mergeability
,
reviewers
:
this
.
_existingReviewers
,
isDraft
:
pullRequest
.
isDraft
,
mergeMethodsAvailability
,
defaultMergeMethod
,
hasReviewDraft
,
autoMerge
:
pullRequest
.
autoMerge
,
allowAutoMerge
:
pullRequest
.
allowAutoMerge
,
autoMergeMethod
:
pullRequest
.
autoMergeMethod
,
mergeQueueMethod
:
mergeQueueMethod
,
mergeQueueEntry
:
pullRequest
.
mergeQueueEntry
,
mergeCommitMeta
:
pullRequest
.
mergeCommitMeta
,
squashCommitMeta
:
pullRequest
.
squashCommitMeta
,
isIssue
:
false
,
emailForCommit
,
currentUserReviewState
:
reviewState
,
revertable
:
pullRequest
.
state
===
GithubItemStateEnum
.
Merged
,
isCopilotOnMyBehalf
:
await
isCopilotOnMyBehalf
(
pullRequest
,
currentUser
,
coAuthors
)
}
;
this
.
_postMessage
(
{
command
:
'pr.initialize'
,
pullrequest
:
context
}
)
;
if
(
pullRequest
.
isResolved
(
)
)
{
this
.
_folderRepositoryManager
.
checkBranchUpToDate
(
pullRequest
,
true
)
;
}
}
catch
(
e
)
{
vscode
.
window
.
showErrorMessage
(
`Error updating pull request description:
${
formatError
(
e
)
}
`
)
;
}
}
public
override
async
update
(
folderRepositoryManager
:
FolderRepositoryManager
,
pullRequestModel
:
PullRequestModel
,
)
:
Promise
<
void
>
{
const
result
=
super
.
update
(
folderRepositoryManager
,
pullRequestModel
,
'pr:github'
)
;
if
(
this
.
_folderRepositoryManager
!==
folderRepositoryManager
)
{
this
.
registerPrListeners
(
)
;
}
await
result
;
// Notify that this PR overview is now active
PullRequestOverviewPanel
.
_onVisible
.
fire
(
pullRequestModel
)
;
return
result
;
}
protected
override
async
_onDidReceiveMessage
(
message
:
IRequestMessage
<
any
>
)
{
const
result
=
await
super
.
_onDidReceiveMessage
(
message
)
;
if
(
result
!==
this
.
MESSAGE_UNHANDLED
)
{
return
;
}
switch
(
message
.
command
)
{
case
'pr.checkout'
:
return
this
.
checkoutPullRequest
(
message
)
;
case
'pr.merge'
:
return
this
.
mergePullRequest
(
message
)
;
case
'pr.change-email'
:
return
this
.
changeEmail
(
message
)
;
case
'pr.deleteBranch'
:
return
this
.
deleteBranch
(
message
)
;
case
'pr.readyForReview'
:
return
this
.
setReadyForReview
(
message
)
;
case
'pr.approve'
:
return
this
.
approvePullRequestMessage
(
message
)
;
case
'pr.request-changes'
:
return
this
.
requestChangesMessage
(
message
)
;
case
'pr.checkout-default-branch'
:
return
this
.
checkoutDefaultBranch
(
message
)
;
case
'pr.apply-patch'
:
return
this
.
applyPatch
(
message
)
;
case
'pr.open-diff'
:
return
this
.
openDiff
(
message
)
;
case
'pr.open-changes'
:
return
this
.
openChanges
(
message
)
;
case
'pr.resolve-comment-thread'
:
return
this
.
resolveCommentThread
(
message
)
;
case
'pr.checkMergeability'
:
return
this
.
_replyMessage
(
message
,
await
this
.
_item
.
getMergeability
(
)
)
;
case
'pr.change-reviewers'
:
return
this
.
changeReviewers
(
message
)
;
case
'pr.update-automerge'
:
return
this
.
updateAutoMerge
(
message
)
;
case
'pr.dequeue'
:
return
this
.
dequeue
(
message
)
;
case
'pr.enqueue'
:
return
this
.
enqueue
(
message
)
;
case
'pr.update-branch'
:
return
this
.
updateBranch
(
message
)
;
case
'pr.gotoChangesSinceReview'
:
return
this
.
gotoChangesSinceReview
(
message
)
;
case
'pr.re-request-review'
:
return
this
.
reRequestReview
(
message
)
;
case
'pr.revert'
:
return
this
.
revert
(
message
)
;
case
'pr.open-session-log'
:
return
this
.
openSessionLog
(
message
)
;
case
'pr.cancel-coding-agent'
:
return
this
.
cancelCodingAgent
(
message
)
;
case
'pr.openCommitChanges'
:
return
this
.
openCommitChanges
(
message
)
;
}
}
private
gotoChangesSinceReview
(
message
:
IRequestMessage
<
void
>
)
:
Promise
<
void
>
{
if
(
!
this
.
_item
.
showChangesSinceReview
)
{
this
.
_item
.
showChangesSinceReview
=
true
;
}
else
{
PullRequestModel
.
openChanges
(
this
.
_folderRepositoryManager
,
this
.
_item
)
;
}
return
this
.
_replyMessage
(
message
,
{
}
)
;
}
private
async
changeReviewers
(
message
:
IRequestMessage
<
void
>
)
:
Promise
<
void
>
{
let
quickPick
:
vscode
.
QuickPick
<
vscode
.
QuickPickItem
&
{
user
?:
IAccount
|
ITeam
|
undefined
;
}
>
|
undefined
;
try
{
quickPick
=
await
reviewersQuickPick
(
this
.
_folderRepositoryManager
,
this
.
_item
.
remote
.
remoteName
,
this
.
_item
.
base
.
isInOrganization
,
this
.
_teamsCount
,
this
.
_item
.
author
,
this
.
_existingReviewers
,
this
.
_item
.
suggestedReviewers
)
;
quickPick
.
busy
=
false
;
const
acceptPromise
:
Promise
<
(
IAccount
|
ITeam
)
[
]
>
=
asPromise
<
void
>
(
quickPick
.
onDidAccept
)
.
then
(
(
)
=>
{
const
pickedReviewers
:
(
IAccount
|
ITeam
)
[
]
|
undefined
=
quickPick
?.
selectedItems
.
filter
(
item
=>
item
.
user
)
.
map
(
item
=>
item
.
user
)
as
(
IAccount
|
ITeam
)
[
]
;
const
botReviewers
=
this
.
_existingReviewers
.
filter
(
reviewer
=>
!
isITeam
(
reviewer
.
reviewer
)
&&
reviewer
.
reviewer
.
accountType
===
'Bot'
)
.
map
(
reviewer
=>
reviewer
.
reviewer
)
;
return
pickedReviewers
.
concat
(
botReviewers
)
;
}
)
;
const
hidePromise
=
asPromise
<
void
>
(
quickPick
.
onDidHide
)
;
const
allReviewers
=
await
Promise
.
race
<
(
IAccount
|
ITeam
)
[
]
|
void
>
(
[
acceptPromise
,
hidePromise
]
)
;
quickPick
.
busy
=
true
;
quickPick
.
enabled
=
false
;
if
(
allReviewers
)
{
const
newUserReviewers
:
IAccount
[
]
=
[
]
;
const
newTeamReviewers
:
ITeam
[
]
=
[
]
;
allReviewers
.
forEach
(
reviewer
=>
{
const
newReviewers
:
(
IAccount
|
ITeam
)
[
]
=
isITeam
(
reviewer
)
?
newTeamReviewers
:
newUserReviewers
;
newReviewers
.
push
(
reviewer
)
;
}
)
;
const
removedUserReviewers
:
IAccount
[
]
=
[
]
;
const
removedTeamReviewers
:
ITeam
[
]
=
[
]
;
this
.
_existingReviewers
.
forEach
(
existing
=>
{
let
newReviewers
:
(
IAccount
|
ITeam
)
[
]
=
isITeam
(
existing
.
reviewer
)
?
newTeamReviewers
:
newUserReviewers
;
let
removedReviewers
:
(
IAccount
|
ITeam
)
[
]
=
isITeam
(
existing
.
reviewer
)
?
removedTeamReviewers
:
removedUserReviewers
;
if
(
!
newReviewers
.
find
(
newTeamReviewer
=>
newTeamReviewer
.
id
===
existing
.
reviewer
.
id
)
)
{
removedReviewers
.
push
(
existing
.
reviewer
)
;
}
}
)
;
await
this
.
_item
.
requestReview
(
newUserReviewers
,
newTeamReviewers
)
;
await
this
.
_item
.
deleteReviewRequest
(
removedUserReviewers
,
removedTeamReviewers
)
;
const
addedReviewers
:
ReviewState
[
]
=
allReviewers
.
map
(
selected
=>
{
return
{
reviewer
:
selected
,
state
:
'REQUESTED'
,
}
;
}
)
;
this
.
_existingReviewers
=
addedReviewers
;
await
this
.
_replyMessage
(
message
,
{
reviewers
:
addedReviewers
,
}
)
;
}
}
catch
(
e
)
{
Logger
.
error
(
formatError
(
e
)
,
PullRequestOverviewPanel
.
ID
)
;
vscode
.
window
.
showErrorMessage
(
formatError
(
e
)
)
;
}
finally
{
quickPick
?.
hide
(
)
;
quickPick
?.
dispose
(
)
;
}
}
private
async
applyPatch
(
message
:
IRequestMessage
<
{
comment
:
IComment
}
>
)
:
Promise
<
void
>
{
try
{
const
comment
=
message
.
args
.
comment
;
const
regex
=
/
`
`
`
d
i
f
f
\n
(
[
\s
\S
]
*
)
\n
`
`
`
/
g
;
const
matches
=
regex
.
exec
(
comment
.
body
)
;
const
tempUri
=
vscode
.
Uri
.
joinPath
(
this
.
_folderRepositoryManager
.
repository
.
rootUri
,
'.git'
,
`
${
comment
.
id
}
.diff`
)
;
const
encoder
=
new
TextEncoder
(
)
;
await
vscode
.
workspace
.
fs
.
writeFile
(
tempUri
,
encoder
.
encode
(
matches
!
[
1
]
)
)
;
await
this
.
_folderRepositoryManager
.
repository
.
apply
(
tempUri
.
fsPath
)
;
await
vscode
.
workspace
.
fs
.
delete
(
tempUri
)
;
vscode
.
window
.
showInformationMessage
(
'Patch applied!'
)
;
}
catch
(
e
)
{
Logger
.
error
(
`Applying patch failed:
${
e
}
`
,
PullRequestOverviewPanel
.
ID
)
;
vscode
.
window
.
showErrorMessage
(
`Applying patch failed:
${
formatError
(
e
)
}
`
)
;
}
}
protected
override
_getTimeline
(
)
:
Promise
<
TimelineEvent
[
]
>
{
return
this
.
_item
.
getTimelineEvents
(
this
.
_item
)
;
}
private
async
openDiff
(
message
:
IRequestMessage
<
{
comment
:
IComment
}
>
)
:
Promise
<
void
>
{
try
{
const
comment
=
message
.
args
.
comment
;
return
PullRequestModel
.
openDiffFromComment
(
this
.
_folderRepositoryManager
,
this
.
_item
,
comment
)
;
}
catch
(
e
)
{
Logger
.
error
(
`Open diff view failed:
${
formatError
(
e
)
}
`
,
PullRequestOverviewPanel
.
ID
)
;
}
}
private
async
openSessionLog
(
message
:
IRequestMessage
<
{
link
:
SessionLinkInfo
}
>
)
:
Promise
<
void
>
{
try
{
await
SessionLogViewManager
.
instance
?.
openForPull
(
this
.
_item
,
message
.
args
.
link
,
message
.
args
.
link
.
openToTheSide
??
false
)
;
}
catch
(
e
)
{
Logger
.
error
(
`Open session log view failed:
${
formatError
(
e
)
}
`
,
PullRequestOverviewPanel
.
ID
)
;
}
}
private
async
cancelCodingAgent
(
message
:
IRequestMessage
<
TimelineEvent
>
)
:
Promise
<
void
>
{
try
{
let
result
=
false
;
if
(
message
.
args
.
event
!==
EventType
.
CopilotStarted
)
{
return
this
.
_replyMessage
(
message
,
{
success
:
false
,
error
:
'Invalid event type'
}
)
;
}
else
{
const
copilotApi
=
await
getCopilotApi
(
this
.
_folderRepositoryManager
.
credentialStore
,
this
.
_telemetry
,
this
.
_item
.
remote
.
authProviderId
)
;
if
(
copilotApi
)
{
const
session
=
(
await
copilotApi
.
getAllSessions
(
this
.
_item
.
id
)
)
[
0
]
;
if
(
session
.
state
!==
'completed'
)
{
result
=
await
this
.
_item
.
githubRepository
.
cancelWorkflow
(
session
.
workflow_run_id
)
;
}
}
}
// need to wait until we get the updated timeline events
let
events
:
TimelineEvent
[
]
=
[
]
;
if
(
result
)
{
do
{
events
=
await
this
.
_getTimeline
(
)
;
}
while
(
copilotEventToStatus
(
mostRecentCopilotEvent
(
events
)
)
!==
CopilotPRStatus
.
Completed
&&
await
new
Promise
<
boolean
>
(
c
=>
setTimeout
(
(
)
=>
c
(
true
)
,
2000
)
)
)
;
}
const
reply
:
CancelCodingAgentReply
=
{
events
}
;
this
.
_replyMessage
(
message
,
reply
)
;
}
catch
(
e
)
{
Logger
.
error
(
`Cancelling coding agent failed:
${
formatError
(
e
)
}
`
,
PullRequestOverviewPanel
.
ID
)
;
vscode
.
window
.
showErrorMessage
(
vscode
.
l10n
.
t
(
'Cannot cancel coding agent'
)
)
;
const
reply
:
CancelCodingAgentReply
=
{
events
:
[
]
,
}
;
this
.
_replyMessage
(
message
,
reply
)
;
}
}
private
async
openCommitChanges
(
message
:
IRequestMessage
<
OpenCommitChangesArgs
>
)
:
Promise
<
void
>
{
try
{
const
{
commitSha
}
=
message
.
args
;
await
PullRequestModel
.
openCommitChanges
(
this
.
_item
.
githubRepository
,
commitSha
)
;
this
.
_replyMessage
(
message
,
{
}
)
;
}
catch
(
error
)
{
Logger
.
error
(
`Failed to open commit changes:
${
formatError
(
error
)
}
`
,
PullRequestOverviewPanel
.
ID
)
;
vscode
.
window
.
showErrorMessage
(
vscode
.
l10n
.
t
(
'Failed to open commit changes: {0}'
,
formatError
(
error
)
)
)
;
}
}
private
async
openChanges
(
message
?:
IRequestMessage
<
{
openToTheSide
?:
boolean
}
>
)
:
Promise
<
void
>
{
const
openToTheSide
=
message
?.
args
?.
openToTheSide
||
false
;
return
PullRequestModel
.
openChanges
(
this
.
_folderRepositoryManager
,
this
.
_item
,
openToTheSide
)
;
}
private
async
resolveCommentThread
(
message
:
IRequestMessage
<
{
threadId
:
string
,
toResolve
:
boolean
,
thread
:
IComment
[
]
}
>
)
{
try
{
if
(
message
.
args
.
toResolve
)
{
await
this
.
_item
.
resolveReviewThread
(
message
.
args
.
threadId
)
;
}
else
{
await
this
.
_item
.
unresolveReviewThread
(
message
.
args
.
threadId
)
;
}
const
timelineEvents
=
await
this
.
_getTimeline
(
)
;
this
.
_replyMessage
(
message
,
timelineEvents
)
;
}
catch
(
e
)
{
vscode
.
window
.
showErrorMessage
(
e
)
;
this
.
_replyMessage
(
message
,
undefined
)
;
}
}
private
checkoutPullRequest
(
message
:
IRequestMessage
<
any
>
)
:
void
{
vscode
.
commands
.
executeCommand
(
'pr.pick'
,
this
.
_item
)
.
then
(
(
)
=>
{
const
isCurrentlyCheckedOut
=
this
.
_item
.
equals
(
this
.
_folderRepositoryManager
.
activePullRequest
)
;
this
.
_replyMessage
(
message
,
{
isCurrentlyCheckedOut
:
isCurrentlyCheckedOut
}
)
;
}
,
(
)
=>
{
const
isCurrentlyCheckedOut
=
this
.
_item
.
equals
(
this
.
_folderRepositoryManager
.
activePullRequest
)
;
this
.
_replyMessage
(
message
,
{
isCurrentlyCheckedOut
:
isCurrentlyCheckedOut
}
)
;
}
,
)
;
}
private
mergePullRequest
(
message
:
IRequestMessage
<
MergeArguments
>
,
)
:
void
{
const
{
title
,
description
,
method
,
email
}
=
message
.
args
;
this
.
_folderRepositoryManager
.
mergePullRequest
(
this
.
_item
,
title
,
description
,
method
,
email
)
.
then
(
result
=>
{
vscode
.
commands
.
executeCommand
(
'pr.refreshList'
)
;
if
(
!
result
.
merged
)
{
vscode
.
window
.
showErrorMessage
(
`Merging PR failed:
${
result
.
message
}
`
)
;
}
const
mergeResult
:
MergeResult
=
{
state
:
result
.
merged
?
GithubItemStateEnum
.
Merged
:
GithubItemStateEnum
.
Open
,
revertable
:
result
.
merged
,
events
:
result
.
timeline
}
;
this
.
_replyMessage
(
message
,
mergeResult
)
;
}
)
.
catch
(
e
=>
{
vscode
.
window
.
showErrorMessage
(
`Unable to merge pull request.
${
formatError
(
e
)
}
`
)
;
this
.
_throwError
(
message
,
''
)
;
}
)
;
}
private
async
changeEmail
(
message
:
IRequestMessage
<
string
>
)
:
Promise
<
void
>
{
const
email
=
await
pickEmail
(
this
.
_item
.
githubRepository
,
message
.
args
)
;
if
(
email
)
{
this
.
_folderRepositoryManager
.
saveLastUsedEmail
(
email
)
;
}
return
this
.
_replyMessage
(
message
,
email
??
message
.
args
)
;
}
private
async
deleteBranch
(
message
:
IRequestMessage
<
any
>
)
{
const
result
=
await
PullRequestView
.
deleteBranch
(
this
.
_folderRepositoryManager
,
this
.
_item
)
;
if
(
result
.
isReply
)
{
this
.
_replyMessage
(
message
,
result
.
message
)
;
}
else
{
this
.
refreshPanel
(
)
;
this
.
_postMessage
(
result
.
message
)
;
}
}
private
setReadyForReview
(
message
:
IRequestMessage
<
{
}
>
)
:
void
{
this
.
_item
.
setReadyForReview
(
)
.
then
(
result
=>
{
this
.
_replyMessage
(
message
,
result
)
;
}
)
.
catch
(
e
=>
{
vscode
.
window
.
showErrorMessage
(
`Unable to set PR ready for review.
${
formatError
(
e
)
}
`
)
;
this
.
_throwError
(
message
,
''
)
;
}
)
;
}
private
async
checkoutDefaultBranch
(
message
:
IRequestMessage
<
string
>
)
:
Promise
<
void
>
{
try
{
const
prBranch
=
this
.
_folderRepositoryManager
.
repository
.
state
.
HEAD
?.
name
;
await
this
.
_folderRepositoryManager
.
checkoutDefaultBranch
(
message
.
args
)
;
if
(
prBranch
)
{
await
this
.
_folderRepositoryManager
.
cleanupAfterPullRequest
(
prBranch
,
this
.
_item
)
;
}
}
finally
{
// Complete webview promise so that button becomes enabled again
this
.
_replyMessage
(
message
,
{
}
)
;
}
}
private
updateReviewers
(
review
?:
ReviewEvent
)
:
void
{
if
(
review
&&
review
.
state
)
{
const
existingReviewer
=
this
.
_existingReviewers
.
find
(
reviewer
=>
review
.
user
.
login
===
(
reviewer
.
reviewer
as
IAccount
)
.
login
,
)
;
if
(
existingReviewer
)
{
existingReviewer
.
state
=
review
.
state
;
}
else
{
this
.
_existingReviewers
.
push
(
{
reviewer
:
review
.
user
,
state
:
review
.
state
,
}
)
;
}
}
}
private
async
doReviewCommand
(
context
:
{
body
:
string
}
,
reviewType
:
ReviewType
,
action
:
(
body
:
string
)
=>
Promise
<
ReviewEvent
>
)
{
const
submittingMessage
=
{
command
:
'pr.submitting-review'
,
lastReviewType
:
reviewType
}
;
this
.
_postMessage
(
submittingMessage
)
;
try
{
const
review
=
await
action
(
context
.
body
)
;
this
.
updateReviewers
(
review
)
;
const
allEvents
=
await
this
.
_getTimeline
(
)
;
const
reviewMessage
:
SubmitReviewReply
&
{
command
:
string
}
=
{
command
:
'pr.append-review'
,
reviewedEvent
:
review
,
events
:
allEvents
,
reviewers
:
this
.
_existingReviewers
}
;
this
.
tryScheduleCopilotRefresh
(
review
.
body
,
review
.
state
)
;
await
this
.
_postMessage
(
reviewMessage
)
;
}
catch
(
e
)
{
vscode
.
window
.
showErrorMessage
(
vscode
.
l10n
.
t
(
'Submitting review failed. {0}'
,
formatError
(
e
)
)
)
;
this
.
_throwError
(
undefined
,
`
${
formatError
(
e
)
}
`
)
;
}
finally
{
this
.
_postMessage
(
{
command
:
'pr.append-review'
}
)
;
}
}
private
async
doReviewMessage
(
message
:
IRequestMessage
<
string
>
,
action
:
(
body
)
=>
Promise
<
ReviewEvent
>
)
{
try
{
const
review
=
await
action
(
message
.
args
)
;
this
.
updateReviewers
(
review
)
;
const
allEvents
=
await
this
.
_getTimeline
(
)
;
const
reply
:
SubmitReviewReply
=
{
reviewedEvent
:
review
,
events
:
allEvents
,
reviewers
:
this
.
_existingReviewers
,
}
;
this
.
tryScheduleCopilotRefresh
(
review
.
body
,
review
.
state
)
;
this
.
_replyMessage
(
message
,
reply
)
;
}
catch
(
e
)
{
vscode
.
window
.
showErrorMessage
(
vscode
.
l10n
.
t
(
'Submitting review failed. {0}'
,
formatError
(
e
)
)
)
;
this
.
_throwError
(
message
,
`
${
formatError
(
e
)
}
`
)
;
}
}
private
approvePullRequest
(
body
:
string
)
:
Promise
<
ReviewEvent
>
{
return
this
.
_item
.
approve
(
this
.
_folderRepositoryManager
.
repository
,
body
)
;
}
private
approvePullRequestMessage
(
message
:
IRequestMessage
<
string
>
)
:
Promise
<
void
>
{
return
this
.
doReviewMessage
(
message
,
(
body
)
=>
this
.
approvePullRequest
(
body
)
)
;
}
private
approvePullRequestCommand
(
context
:
{
body
:
string
}
)
:
Promise
<
void
>
{
return
this
.
doReviewCommand
(
context
,
ReviewType
.
Approve
,
(
body
)
=>
this
.
approvePullRequest
(
body
)
)
;
}
private
requestChanges
(
body
:
string
)
:
Promise
<
ReviewEvent
>
{
return
this
.
_item
.
requestChanges
(
body
)
;
}
private
requestChangesCommand
(
context
:
{
body
:
string
}
)
:
Promise
<
void
>
{
return
this
.
doReviewCommand
(
context
,
ReviewType
.
RequestChanges
,
(
body
)
=>
this
.
requestChanges
(
body
)
)
;
}
private
requestChangesMessage
(
message
:
IRequestMessage
<
string
>
)
:
Promise
<
void
>
{
return
this
.
doReviewMessage
(
message
,
(
body
)
=>
this
.
requestChanges
(
body
)
)
;
}
private
submitReview
(
body
:
string
)
:
Promise
<
ReviewEvent
>
{
return
this
.
_item
.
submitReview
(
ReviewEventEnum
.
Comment
,
body
)
;
}
private
submitReviewCommand
(
context
:
{
body
:
string
}
)
{
return
this
.
doReviewCommand
(
context
,
ReviewType
.
Comment
,
(
body
)
=>
this
.
submitReview
(
body
)
)
;
}
protected
override
submitReviewMessage
(
message
:
IRequestMessage
<
string
>
)
{
return
this
.
doReviewMessage
(
message
,
(
body
)
=>
this
.
submitReview
(
body
)
)
;
}
private
reRequestReview
(
message
:
IRequestMessage
<
string
>
)
:
void
{
let
targetReviewer
:
ReviewState
|
undefined
;
const
userReviewers
:
IAccount
[
]
=
[
]
;
const
teamReviewers
:
ITeam
[
]
=
[
]
;
for
(
const
reviewer
of
this
.
_existingReviewers
)
{
let
id
=
reviewer
.
reviewer
.
id
;
if
(
id
&&
(
(
reviewer
.
state
===
'REQUESTED'
)
||
(
id
===
message
.
args
)
)
)
{
if
(
id
===
message
.
args
)
{
targetReviewer
=
reviewer
;
}
}
}
if
(
targetReviewer
&&
isITeam
(
targetReviewer
.
reviewer
)
)
{
teamReviewers
.
push
(
targetReviewer
.
reviewer
)
;
}
else
if
(
targetReviewer
&&
!
isITeam
(
targetReviewer
.
reviewer
)
)
{
userReviewers
.
push
(
targetReviewer
.
reviewer
)
;
}
this
.
_item
.
requestReview
(
userReviewers
,
teamReviewers
,
true
)
.
then
(
(
)
=>
{
if
(
targetReviewer
)
{
targetReviewer
.
state
=
'REQUESTED'
;
}
this
.
_replyMessage
(
message
,
{
reviewers
:
this
.
_existingReviewers
,
}
)
;
}
)
;
}
private
async
revert
(
message
:
IRequestMessage
<
string
>
)
:
Promise
<
void
>
{
await
this
.
_folderRepositoryManager
.
createPullRequestHelper
.
revert
(
this
.
_telemetry
,
this
.
_extensionUri
,
this
.
_folderRepositoryManager
,
this
.
_item
,
async
(
pullRequest
)
=>
{
const
result
:
Partial
<
PullRequest
>
=
{
revertable
:
!
pullRequest
}
;
return
this
.
_replyMessage
(
message
,
result
)
;
}
)
;
}
private
async
updateAutoMerge
(
message
:
IRequestMessage
<
{
autoMerge
?:
boolean
,
autoMergeMethod
:
MergeMethod
}
>
)
:
Promise
<
void
>
{
let
replyMessage
:
{
autoMerge
:
boolean
,
autoMergeMethod
?:
MergeMethod
}
;
if
(
!
message
.
args
.
autoMerge
&&
!
this
.
_item
.
autoMerge
)
{
replyMessage
=
{
autoMerge
:
false
}
;
}
else
if
(
(
message
.
args
.
autoMerge
===
false
)
&&
this
.
_item
.
autoMerge
)
{
await
this
.
_item
.
disableAutoMerge
(
)
;
replyMessage
=
{
autoMerge
:
this
.
_item
.
autoMerge
}
;
}
else
{
if
(
this
.
_item
.
autoMerge
&&
message
.
args
.
autoMergeMethod
!==
this
.
_item
.
autoMergeMethod
)
{
await
this
.
_item
.
disableAutoMerge
(
)
;
}
await
this
.
_item
.
enableAutoMerge
(
message
.
args
.
autoMergeMethod
)
;
replyMessage
=
{
autoMerge
:
this
.
_item
.
autoMerge
,
autoMergeMethod
:
this
.
_item
.
autoMergeMethod
}
;
}
this
.
_replyMessage
(
message
,
replyMessage
)
;
}
private
async
dequeue
(
message
:
IRequestMessage
<
void
>
)
:
Promise
<
void
>
{
const
result
=
await
this
.
_item
.
dequeuePullRequest
(
)
;
this
.
_replyMessage
(
message
,
result
)
;
}
private
async
enqueue
(
message
:
IRequestMessage
<
void
>
)
:
Promise
<
void
>
{
const
result
=
await
this
.
_item
.
enqueuePullRequest
(
)
;
this
.
_replyMessage
(
message
,
{
mergeQueueEntry
:
result
}
)
;
}
private
async
updateBranch
(
message
:
IRequestMessage
<
string
>
)
:
Promise
<
void
>
{
if
(
!
this
.
isUpdateBranchWithGitHubEnabled
(
)
)
{
await
vscode
.
window
.
showErrorMessage
(
vscode
.
l10n
.
t
(
'The pull request branch must be checked out to be updated.'
)
,
{
modal
:
true
}
)
;
return
this
.
_replyMessage
(
message
,
{
}
)
;
}
if
(
this
.
_folderRepositoryManager
.
repository
.
state
.
workingTreeChanges
.
length
>
0
||
this
.
_folderRepositoryManager
.
repository
.
state
.
indexChanges
.
length
>
0
)
{
await
vscode
.
window
.
showErrorMessage
(
vscode
.
l10n
.
t
(
'The pull request branch cannot be updated when the there changed files in the working tree or index. Stash or commit all change and then try again.'
)
,
{
modal
:
true
}
)
;
return
this
.
_replyMessage
(
message
,
{
}
)
;
}
const
mergeSucceeded
=
await
this
.
_folderRepositoryManager
.
tryMergeBaseIntoHead
(
this
.
_item
,
true
)
;
if
(
!
mergeSucceeded
)
{
this
.
_replyMessage
(
message
,
{
}
)
;
}
// The mergability of the PR doesn't update immediately. Poll.
let
mergability
=
PullRequestMergeability
.
Unknown
;
let
attemptsRemaining
=
5
;
do
{
mergability
=
(
await
this
.
_item
.
getMergeability
(
)
)
.
mergeability
;
attemptsRemaining
--
;
await
new
Promise
(
c
=>
setTimeout
(
c
,
1000
)
)
;
}
while
(
attemptsRemaining
>
0
&&
mergability
===
PullRequestMergeability
.
Unknown
)
;
const
result
:
Partial
<
PullRequest
>
=
{
events
:
await
this
.
_getTimeline
(
)
,
mergeable
:
mergability
,
}
;
await
this
.
refreshPanel
(
)
;
this
.
_replyMessage
(
message
,
result
)
;
}
protected
override
editCommentPromise
(
comment
:
IComment
,
text
:
string
)
:
Promise
<
IComment
>
{
return
this
.
_item
.
editReviewComment
(
comment
,
text
)
;
}
protected
override
deleteCommentPromise
(
comment
:
IComment
)
:
Promise
<
void
>
{
return
this
.
_item
.
deleteReviewComment
(
comment
.
id
.
toString
(
)
)
;
}
override
dispose
(
)
{
super
.
dispose
(
)
;
disposeAll
(
this
.
_prListeners
)
;
}
/**
* Static dispose method to clean up static resources
*/
public
static
dispose
(
)
{
PullRequestOverviewPanel
.
_onVisible
.
dispose
(
)
;
}
}
export
function
getDefaultMergeMethod
(
methodsAvailability
:
MergeMethodsAvailability
,
)
:
MergeMethod
{
const
userPreferred
=
vscode
.
workspace
.
getConfiguration
(
PR_SETTINGS_NAMESPACE
)
.
get
<
MergeMethod
>
(
DEFAULT_MERGE_METHOD
)
;
// Use default merge method specified by user if it is available
if
(
userPreferred
&&
methodsAvailability
.
hasOwnProperty
(
userPreferred
)
&&
methodsAvailability
[
userPreferred
]
)
{
return
userPreferred
;
}
const
methods
:
MergeMethod
[
]
=
[
'merge'
,
'squash'
,
'rebase'
]
;
// GitHub requires to have at least one merge method to be enabled; use first available as default
return
methods
.
find
(
method
=>
methodsAvailability
[
method
]
)
!
;
}
Back
|
FazBrowse Home
|
New Git URL