ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / src / vs / platform / github / common / githubQueryServiceImpl.ts 1511 строк · изменён 14 нояб., 04:52
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
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
import { raceCancellationError } from '../../../base/common/async.js' ;
import { CancellationToken } from '../../../base/common/cancellation.js' ;
import { Disposable } from '../../../base/common/lifecycle.js' ;
import { ISettableObservable, observableValue } from '../../../base/common/observable.js' ;
import { hasKey } from '../../../base/common/types.js' ;
import { ILogService } from '../../log/common/log.js' ;
import {
GitHubChangedFile,
GitHubComparison,
GitHubComparisonCommit,
GitHubHydratableResourceRef,
GitHubIssue,
GitHubIssueRef
GitHubIssueResource
GitHubIssueSubscription
GitHubPullRequestContext
GitHubPullRequestContextComment
GitHubPullRequestLookup
GitHubPullRequestsPage
GitHubPullRequestSummary
GitHubQueryApi
GitHubRecentIssue
GitHubRecentPullRequest
GitHubRecentPullRequestReviewThread
GitHubRepository
GitHubRepositoryRef
GitHubRepositoryResource
GitHubRepositorySubscription
GitHubResourcePriority
GitHubResourceSubscriptionOptions
FragmentState GitHubActor PullRequestRef
GitHubCredential GitHubCredentialInvalidation IGitHubCredentials
IGitHubCapabilities
IGitHubScheduler systemGitHubScheduler
GitHubGraphQLError GitHubRequestError IGitHubTransport
GitHubBackoffPolicy gitHubBackoffDelay
IGitHubEndpointProvider
PullRequestScheduler
dormantGrace
maximumDormantEntries
visible
background
failureBackoff GitHubBackoffPolicy
jitter
defaultPollingPolicy GitHubEntityPollingPolicy
dormantGrace
maximumDormantEntries
visible
background
failureBackoff immediateRetries base maximum jitter
jitter
maximumPaginationPages
maximumHydrationBatchSize
repositoryHydrationFields
issueHydrationFields
maximumCommitPullRequests
maximumIssueLinkageBatchSize
listPullRequestsQuery
searchPullRequestsQuery
recentIssuesQuery
recentPullRequestsQuery
reviewThreadSummaryQuery
GitHubRepositoryRef GitHubIssueRef
GitHubRepository GitHubIssue
controller AbortController
promise
state ISettableObservable FragmentState TValue
resource GitHubRepositoryResource GitHubIssueResource
subscriptions
keys
operation IEntityOperation
dormantAt
failureCount
generation
disposed
id
kind EntityKind
ref TRef
ref ref
state status complete
resource kind
EntityEntry GitHubRepositoryRef GitHubRepository
EntityEntry GitHubIssueRef GitHubIssue
attemptedAt
state
state
status
complete
attemptedAt
error
error NonNullable FragmentState TValue
state
state
status
complete
error
ref TRef
_entry EntityEntry GitHubRepositoryRef GitHubRepository
GitHubRepositoryRef
_entry ref
ISettableObservable FragmentState GitHubRepository
_entry state
_entry EntityEntry GitHubIssueRef GitHubIssue
GitHubIssueRef
_entry ref
ISettableObservable FragmentState GitHubIssue
_entry state
_disposed
resource TRef GitHubIssueResource GitHubRepositoryResource
entry EntityEntry TRef TValue
_service GitHubQueryService
options GitHubResourceSubscriptionOptions
options options
options GitHubResourceSubscriptionOptions
options GitHubResourceSubscriptionOptions
_disposed entry disposed
options options
_service entry
token CancellationToken CancellationToken None
_disposed entry disposed
_service entry token
_disposed
_disposed
_service
_entriesByKey
_entries
_dormant
_unsupportedGraphQLQueries
_scheduler PullRequestScheduler
_clock IGitHubScheduler
_entryId
scheduler IGitHubScheduler
_policy GitHubEntityPollingPolicy defaultPollingPolicy
_credentials IGitHubCredentials
_transport IGitHubTransport
_endpoint IGitHubEndpointProvider
_capabilities IGitHubCapabilities
_logService ILogService
_clock scheduler systemGitHubScheduler
_scheduler _clock
_credentials event event
ref GitHubRepositoryRef options GitHubResourceSubscriptionOptions GitHubRepositorySubscription
normalized ref
entry normalized
subscription entry resource GitHubRepositoryResource entry options
entry subscriptions subscription
_logService
entry
subscription
refs GitHubHydratableResourceRef signal AbortSignal
index
item
entry item kind
item ref
item ref
resource
status resource entry state status
status status
resource resource generation resource entry generation
resources length
firstRef resources item ref
resources resource resource item ref account firstRef
attemptedAt _clock
entry resources
_scheduler entry
entry attemptedAt
definitions
selections
variables Record
index index resources length index
item resources index item
definitions
variables item ref owner
variables item ref repo
item kind
selections
definitions
variables item ref
selections
query
data object
data firstRef query variables signal
error
entry generation resources
entry disposed entry generation generation
entry error
entry subscriptions size
entry _clock
entry
error
observedAt _clock
hydratedCount
index index resources length index
item entry generation resources index
entry disposed entry generation generation
repositoryValue data
item kind
repositoryValue
entry
value repositoryValue
repositoryEntry item ref
repositoryEntry state value status complete observedAt attemptedAt observedAt
repositoryEntry value
repositoryEntry subscriptions size
repositoryEntry
repositoryEntry _clock repositoryEntry
hydratedCount
issueValue repositoryValue repositoryValue
issueValue
entry
value issueValue
issueEntry item ref
issueEntry state value status complete observedAt attemptedAt observedAt
issueEntry subscriptions size
issueEntry
issueEntry
issueEntry _clock issueEntry
hydratedCount
error
entry error
_logService
entry EntityEntry EntityRef EntityValue error
entry state
entry state
status
complete
error error
entry subscriptions size
entry _clock
entry
entry EntityEntry EntityRef EntityValue
entry state
entry state
status
complete
error kind message
entry subscriptions size
entry
ref GitHubIssueRef options GitHubResourceSubscriptionOptions GitHubIssueSubscription
normalized ref
entry normalized
subscription entry resource GitHubIssueResource entry options
entry subscriptions subscription
_logService
entry
subscription
ref GitHubRepositoryRef base head signal AbortSignal GitHubComparison
normalized ref
base head
normalized signal credential combinedSignal
commits GitHubComparisonCommit
files GitHubChangedFile
filesPresent
first object
totalCommits
page page maximumPaginationPages page
response _transport credential account credential token
method
url
etag
priority
combinedSignal
value response data
first value
totalCommits value totalCommits
commits value toComparisonCommit
page
fileValues value
filesPresent fileValues
files fileValues toChangedFile
commits length totalCommits value length
first
mergeBaseSha first
commitsComplete commits length totalCommits
baseSha first
mergeBaseSha
headSha commitsComplete commits sha mergeBaseSha
status first
aheadBy first
behindBy first
totalCommits
commits
commitsComplete
files
filesComplete filesPresent files length
ref GitHubRepositoryRef cursor signal AbortSignal GitHubPullRequestsPage
ref listPullRequestsQuery
owner ref owner
repo ref repo
cursor cursor
signal data
repository data
connection repository
pageInfo connection
pullRequests connection value value
cursor pageInfo
hasNextPage pageInfo
ref GitHubRepositoryRef signal AbortSignal GitHubPullRequestSummary
ref signal
ref GitHubRepositoryRef signal AbortSignal GitHubPullRequestSummary
ref signal
ref PullRequestRef signal AbortSignal GitHubPullRequestContext
repositoryRef ref
repositoryRef signal credential combinedSignal
root
coreResponse files issueComments reviewComments
_transport credential account credential token
method
url repositoryRef root
etag
priority
combinedSignal
repositoryRef credential combinedSignal
repositoryRef credential combinedSignal
repositoryRef credential combinedSignal
pullRequest coreResponse data
base pullRequest
head pullRequest
comments GitHubPullRequestContextComment
issueComments value value
reviewComments value value
left right left createdAt right createdAt left updatedAt right updatedAt
ref
url pullRequest
title pullRequest
description pullRequest
author pullRequest
draft pullRequest
baseRef base
branchName head
headRef head
updatedAt pullRequest
patch files
filesComplete files length
comments
commentsComplete
ref GitHubRepositoryRef
branch
headOwner
signal AbortSignal
GitHubPullRequestLookup
normalized ref
owner headOwner normalized owner
normalized signal credential combinedSignal
response _transport credential account credential token
method
url
etag
priority
combinedSignal
values response data
values length normalized values
ref GitHubRepositoryRef sha signal AbortSignal GitHubPullRequestLookup
normalized ref
normalized signal credential combinedSignal
values
response _transport credential account credential token
method
url
etag
priority
combinedSignal
values response data
error
error error statusCode error responseBody
error
values length maximumCommitPullRequests
atHead values value value sha
open atHead value value
candidates open length open atHead
candidates length normalized candidates
ref GitHubRepositoryRef signal AbortSignal GitHubRecentIssue
ref recentIssuesQuery
query
signal data data
isObject
toRecentIssue
ref GitHubRepositoryRef signal AbortSignal GitHubRecentPullRequest
ref recentPullRequestsQuery
query
signal data data
isObject
toRecentPullRequest
ref PullRequestRef signal AbortSignal GitHubRecentPullRequestReviewThread
result GitHubRecentPullRequestReviewThread
after
page page maximumPaginationPages page
response ref reviewThreadSummaryQuery
owner ref owner
repo ref repo
ref
after
signal
connection response
result connection isObject toReviewThreadSummary
pageInfo connection
pageInfo
result
after pageInfo
ref GitHubRepositoryRef
issueNumbers
signal AbortSignal
normalizedNumbers issueNumbers Number
linked
offset offset normalizedNumbers length offset maximumIssueLinkageBatchSize
batch normalizedNumbers offset offset maximumIssueLinkageBatchSize
variableDefinitions batch _ index
selections batch _ index
query
variables Record owner ref owner repo ref repo
batch index variables
data ref query variables signal
repository data
batch index
issue repository
references issue issue
references references
linked
linked
entry EntityEntry EntityRef EntityValue
entry
entry _clock entry
entry EntityEntry EntityRef EntityValue token CancellationToken
entry disposed entry subscriptions size
_scheduler entry
entry operation
entry operation promise token
controller
entry generation
operation IEntityOperation
controller
promise entry controller
entry operation operation
entry operation
entry operation operation
operation promise token
subscription EntitySubscription EntityRef EntityValue
entry subscription entry
entry subscriptions subscription
entry subscriptions size
entry
entry
entry EntityEntry EntityRef EntityValue
entry dormantAt _clock
_logService
_scheduler entry
entry operation controller
entry operation
_dormant entry id entry
_scheduler entry _clock _policy dormantGrace
entry dormantAt
entry
entry _entries
entry
_scheduler
_unsupportedGraphQLQueries
override
kind EntityKind ref TRef EntityEntry TRef TValue
key kind ref
existing _entriesByKey key
existing
existing EntityEntry TRef TValue
entry _entryId kind ref
entry keys key
_entriesByKey key entry EntityEntry EntityRef EntityValue
_entries entry EntityEntry EntityRef EntityValue
_logService
entry
entry EntityEntry EntityRef EntityValue
resumed
entry dormantAt
entry dormantAt
_dormant entry id
_scheduler entry
resumed
state entry state
state status
state status
state status
resumed entry operation state status
entry _clock
resumed entry
entry _clock entry
entry EntityEntry EntityRef EntityValue controller AbortController
previous entry state
entry state
previous
status
complete
attemptedAt _clock
error
credential GitHubCredential
startedAt _clock
_logService
credential _credentials controller signal
entry ref credential
response _transport credential account credential token
method
url entry kind
entry ref
entry ref
etag
priority entry
AbortSignal controller signal credential signal
entry disposed controller signal aborted entry subscriptions size
value entry kind
response data
response data
entry state
value
status
complete
observedAt _clock
attemptedAt _clock
entry kind
entry EntityEntry GitHubRepositoryRef GitHubRepository value GitHubRepository
_logService
entry failureCount
entry
entry _clock entry _clock _policy jitter
error
credential entry ref credential
_credentials credential error
entry disposed controller signal aborted entry subscriptions size
credential signal aborted
entry _clock
error
entry state
previous
status
complete
attemptedAt _clock
error error
error error kind
entry
_logService
error
ref GitHubRepositoryRef
query
reviewRequested
assigned
signal AbortSignal
GitHubPullRequestSummary
ref searchPullRequestsQuery query signal data
data
isObject
value value reviewRequested assigned
ref GitHubRepositoryRef
query
variables Readonly Record
signal AbortSignal
ref signal credential combinedSignal
capabilities _capabilities credential combinedSignal
capabilities graphql
queryKey
_unsupportedGraphQLQueries queryKey
response _transport
credential account
credential token
_endpoint
query
variables
combinedSignal
response errors
response data
error
error error kind
_unsupportedGraphQLQueries queryKey
error
ref GitHubRepositoryRef
query
variables Readonly Record
signal AbortSignal
data
ref query variables signal
ref GitHubRepositoryRef
credential GitHubCredential
route
signal AbortSignal
result
url
page url page maximumPaginationPages page
response _transport credential account credential token
method
url
etag
priority
signal
values response data
result values
url response link
url values length
url
values length
url
url
result
ref GitHubRepositoryRef
signal AbortSignal
credential GitHubCredential signal AbortSignal
credential _credentials signal
ref credential
credential AbortSignal signal credential signal
error
_credentials credential error
error
entry EntityEntry GitHubRepositoryRef GitHubRepository repository GitHubRepository
owner repo extra repository nameWithOwner
owner repo extra
entry ref entry ref owner repo
alias entry ref
_entriesByKey alias
_entriesByKey alias entry EntityEntry EntityRef EntityValue
entry keys alias
_logService
event GitHubCredentialInvalidation
_logService
entry _entries
event credential entry ref event credential
event reason event reason
current entry state
entry state
current
status current value
complete
error
entry subscriptions size
entry _clock
entry
entry EntityEntry EntityRef EntityValue
entry disposed
entry disposed
_logService
entry operation controller
_scheduler entry
_scheduler entry
key entry keys
_entriesByKey key entry
_entriesByKey key
entry subscriptions
_dormant entry id
_entries entry
_dormant size _policy maximumDormantEntries
oldest _dormant
left right left dormantAt right dormantAt left id right id
oldest
entry EntityEntry EntityRef EntityValue dueAt
entry disposed entry subscriptions size
_scheduler entry dueAt
entry CancellationToken None error
entry disposed entry subscriptions size
_logService error
entry EntityEntry EntityRef EntityValue GitHubResourcePriority
result GitHubResourcePriority
subscription entry subscriptions
subscription options priority
subscription options priority
result
result
entry EntityEntry EntityRef EntityValue
entry _policy background _policy visible
entry EntityEntry EntityRef EntityValue
entry failureCount
delay _policy failureBackoff _clock entry failureCount entry
entry _clock delay
entry EntityEntry EntityRef EntityValue
entry kind
state entry state
state status state value GitHubIssue state
entry EntityEntry EntityRef EntityValue
entry EntityEntry EntityRef EntityValue
ref GitHubRepositoryRef route
suffix route
ref GitHubRepositoryRef GitHubRepositoryRef
host ref host
accountId ref accountId
owner ref owner
repo ref repo
host accountId owner repo
host accountId owner repo
ref GitHubIssueRef GitHubIssueRef
repository ref
Number ref ref
repository ref
kind EntityKind ref EntityRef
kind
ref host
ref accountId
ref owner
ref repo
ref ref
ref GitHubRepositoryRef
credential account host accountId
ref host credential account host ref accountId credential account accountId
priority GitHubResourcePriority
priority
value GitHubRepository
item value
owner item
language item
stars item
id item item
owner owner
name item
nameWithOwner item
language language
stars stars
defaultBranch item
item
description item
url item
archived item
fork item
value object GitHubRepository
owner value
primaryLanguage value
defaultBranch value
stars value
id value
owner owner
name value
nameWithOwner value
primaryLanguage language primaryLanguage
stars stars
defaultBranch defaultBranch defaultBranch
value
description value
url value
archived value
fork value
value object GitHubIssue
author value
assignees value
labels value
stateReason value
id value
value
title value
body value
url value
state value
stateReason stateReason stateReason stateReason stateReason
stateReason
author author author login
assignees assignees isObject requiredActor
labels labels isObject label label
createdAt value
updatedAt value
closedAt value
value GitHubIssue
item value
Reflect item
author item
id item item
item
title item
body item
url item
state item
stateReason item
author author author login
assignees item isObject requiredActor
labels item label
label
label
label
name label
name name
createdAt item
updatedAt item
closedAt item
value GitHubChangedFile
item value
filename item
previousFilename item
status item
additions item
deletions item
changes item
patch item
blobUrl item
value GitHubComparisonCommit
item value
commit item
author item
sha item
message commit
author author author
committedAt commit commit
url item
value reviewRequested assigned GitHubPullRequestSummary
item value
item
author item
title item
author author author login
headRef item
checkoutRef
draft item
updatedAt item
additions item
deletions item
reviewRequestedFromViewer reviewRequested
assignedToViewer assigned
ref GitHubRepositoryRef value GitHubPullRequestLookup
item value
ref ref item
id item
url item
createdAt item
kind value GitHubPullRequestContextComment
item value
kind
author item
body item
createdAt item
updatedAt item
path kind item
line kind item item
values
values value
file value
file
value object GitHubRecentIssue
value
title value
url value
updatedAt value
value object GitHubRecentPullRequest
commits value
node commits isObject
commit node node
rollup commit commit
value
title value
url value
updatedAt value
statusCheckRollupState rollup rollup
latestCommitAt commit commit
value object GitHubRecentPullRequestReviewThread
comments value
latest comments isObject
isResolved value
latestCommentAt latest latest
errors GitHubGraphQLError
errors length
types errors error error type
codes errors error error extensions code
kind types
types type type type
types type type
types type type
codes code code code code
kind
errors
link
link
part link
match part
match groups rel
match groups url
value path object
current value
part path
current current part
current
value message object
value
message
value
value value object
value value value
value message
value
message
value
value object key object
Reflect value key
value object key object
property Reflect value key
property property property
value object key
Reflect value key
value object key
property Reflect value key
property property
property
value object key
property value key
property
property
value object key
property Reflect value key
property property
value object key
property Reflect value key
property property property
value object key
property Reflect value key
property Number property property
value object key
property value key
property
property
value object key
property Reflect value key
property property
value object key
property Reflect value key
property property property
value object key allowed fallback
value object key allowed fallback
value object key allowed fallback
property value key
property allowed property property fallback
value object GitHubActor
login value
id value value
id id login login
error message kind GitHubRequestErrorKind statusCode
error
message error message kind error kind statusCode error statusCode
message error error message error kind
ref EntityRef
error
error
error error name error
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
}
from
'./githubQueryService.js'
;
import
{
,
,
}
from
'./githubPullRequestService.js'
;
import
{
,
,
}
from
'./githubCredentialService.js'
;
import
{
}
from
'./githubHostCapabilitiesService.js'
;
import
{
,
}
from
'./githubScheduler.js'
;
import
{
,
,
}
from
'./githubTransport.js'
;
import
{
,
}
from
'./githubBackoff.js'
;
import
{
}
from
'./githubTypes.js'
;
import
{
}
from
'./pullRequestScheduler.js'
;
export
interface
IGitHubQuery
extends
GitHubQueryApi
{
clear
(
)
:
void
;
}
export
interface
GitHubEntityPollingPolicy
{
readonly
:
number
;
readonly
:
number
;
readonly
:
number
;
readonly
:
number
;
readonly
:
;
readonly
:
number
;
}
const
:
=
{
:
120_000
,
:
50
,
:
60_000
,
:
300_000
,
:
{
:
0
,
:
60_000
,
:
900_000
,
:
5_000
}
,
:
5_000
,
}
;
const
=
100
;
const
=
25
;
const
=
`
id
owner { id login }
name
nameWithOwner
primaryLanguage { name }
stargazerCount
defaultBranchRef { name }
isPrivate
description
url
isArchived
isFork
`
;
const
=
`
id
number
title
body
url
state
stateReason
author { id login }
assignees(first: 100) { nodes { id login } }
labels(first: 100) { nodes { name } }
createdAt
updatedAt
closedAt
`
;
const
=
100
;
const
=
20
;
const
=
` query AgentHostListPullRequests($owner: String!, $repo: String!, $cursor: String) {
repository(owner: $owner, name: $repo) {
pullRequests(first: 100, after: $cursor, states: OPEN, orderBy: { field: UPDATED_AT, direction: DESC }) {
nodes { number title author { login ... on User { databaseId } } headRefName isDraft updatedAt additions deletions }
pageInfo { endCursor hasNextPage }
}
}
rateLimit { limit remaining used resetAt }
} `
;
const
=
` query AgentHostSearchPullRequests($query: String!) {
search(first: 100, query: $query, type: ISSUE) {
nodes {
... on PullRequest {
number title author { login ... on User { databaseId } } headRefName isDraft updatedAt additions deletions
}
}
}
rateLimit { limit remaining used resetAt }
} `
;
const
=
` query AgentHostRecentAssignedIssues($query: String!) {
search(query: $query, type: ISSUE, first: 5) {
nodes { ... on Issue { number title url updatedAt } }
}
rateLimit { limit remaining used resetAt }
} `
;
const
=
` query AgentHostRecentAuthoredPullRequests($query: String!) {
search(query: $query, type: ISSUE, first: 5) {
nodes {
... on PullRequest {
number title url updatedAt
commits(last: 1) {
nodes { commit { committedDate statusCheckRollup { state } } }
}
}
}
}
rateLimit { limit remaining used resetAt }
} `
;
const
=
` query AgentHostPullRequestReviewThreadSummary($owner: String!, $repo: String!, $number: Int!, $after: String) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $number) {
reviewThreads(first: 100, after: $after) {
nodes { isResolved comments(last: 1) { nodes { createdAt } } }
pageInfo { hasNextPage endCursor }
}
}
}
rateLimit { limit remaining used resetAt }
} `
;
type
EntityKind
=
'repository'
|
'issue'
;
type
EntityRef
=
|
;
type
EntityValue
=
|
;
interface
IEntityOperation
{
readonly
:
;
readonly
:
Promise
<
void
>
;
}
class
EntityEntry< TRef extends EntityRef, TValue extends EntityValue>
{
readonly
:
<
<
>>
;
readonly
:
|
;
readonly
=
new
Set< EntitySubscription< TRef, TValue>>
(
)
;
readonly
=
new
Set< string >
(
)
;
:
|
undefined
;
:
number
|
undefined
;
=
0
;
=
0
;
=
false
;
constructor
(
readonly
:
number
,
readonly
:
,
:
,
)
{
this
.
=
;
this
.
=
observableValue
(
this
,
{
:
'missing'
,
:
false
}
)
;
this
.
=
===
'repository'
?
new
RepositoryResourceImpl
(
this
as
<
,
>
)
:
new
IssueResourceImpl
(
this
as
<
,
>
)
;
}
setLoading
(
:
string
)
:
void
{
this
.
.
set
(
{
...
this
.
.
get
(
)
,
:
'loading'
,
:
false
,
,
:
undefined
,
}
,
undefined
)
;
}
setError
(
:
<
<
>
[
'error'
]
>
)
:
void
{
this
.
.
set
(
{
...
this
.
.
get
(
)
,
:
'error'
,
:
false
,
,
}
,
undefined
)
;
}
:
;
}
class
RepositoryResourceImpl
implements
GitHubRepositoryResource
{
constructor
(
private
readonly
:
<
,
>
)
{
}
get
ref
(
)
:
{
return
this
.
.
;
}
get
state
(
)
:
<
<
>>
{
return
this
.
.
;
}
}
class
IssueResourceImpl
implements
GitHubIssueResource
{
constructor
(
private
readonly
:
<
,
>
)
{
}
get
ref
(
)
:
{
return
this
.
.
;
}
get
state
(
)
:
<
<
>>
{
return
this
.
.
;
}
}
class
EntitySubscription< TRef extends EntityRef, TValue extends EntityValue>
{
private
=
false
;
constructor
(
readonly
:
extends
GitHubIssueRef
?
:
,
readonly
:
<
,
>
,
private
readonly
:
,
:
,
)
{
this
.
=
;
}
:
;
update
(
:
)
:
void
{
if
(
this
.
||
this
.
.
)
{
throw
new
Error
(
'GitHub resource subscription has been disposed'
)
;
}
this
.
=
;
this
.
.
updateEntitySubscription
(
this
.
)
;
}
refresh
(
:
=
.
)
:
Promise
<
void
>
{
if
(
this
.
||
this
.
.
)
{
return
Promise
.
reject
(
new
Error
(
'GitHub resource subscription has been disposed'
)
)
;
}
return
this
.
.
refreshEntity
(
this
.
,
)
;
}
dispose
(
)
:
void
{
if
(
this
.
)
{
return
;
}
this
.
=
true
;
this
.
.
removeEntitySubscription
(
this
)
;
}
}
export
class
GitHubQueryService
extends
Disposable
implements
IGitHubQuery
{
private
readonly
=
new
Map< string , EntityEntry< EntityRef, EntityValue>>
(
)
;
private
readonly
=
new
Set< EntityEntry< EntityRef, EntityValue>>
(
)
;
private
readonly
=
new
Map< number , EntityEntry< EntityRef, EntityValue>>
(
)
;
private
readonly
=
new
Set< string >
(
)
;
private
readonly
:
;
private
readonly
:
;
private
=
0
;
constructor
(
:
|
undefined
,
private
readonly
:
=
,
private
readonly
:
,
private
readonly
:
,
private
readonly
:
,
private
readonly
:
,
private
readonly
:
,
)
{
super
(
)
;
this
.
=
??
;
this
.
=
this
.
_register
(
new
PullRequestScheduler
(
this
.
)
)
;
this
.
_register
(
this
.
.
onDidInvalidate
(
=>
this
.
_handleCredentialInvalidation
(
)
)
)
;
}
subscribeRepository
(
:
,
:
)
:
{
const
=
normalizeRepositoryRef
(
)
;
const
=
this
.
_getOrCreateEntity < GitHubRepositoryRef, GitHubRepository>
(
'repository'
,
)
;
const
=
new
EntitySubscription
(
.
as
,
,
this
,
)
;
.
.
add
(
)
;
this
.
.
trace
(
` [GitHubQueryService] Added repository subscription for ${ formatEntityRef ( entry. ref) } (entry ${ entry. id} , subscriptions: ${ entry. subscriptions. size} ) `
)
;
this
.
_activateEntity
(
)
;
return
;
}
async
hydrateResources
(
:
readonly
[
]
,
:
)
:
Promise
<
void
>
{
for
(
let
=
0
;
index < refs. length; index += maximumHydrationBatchSize) {
await this . _hydrateResourceBatch ( refs. slice ( index, index + maximumHydrationBatchSize) , signal) ;
}
}
private async _hydrateResourceBatch ( refs: readonly GitHubHydratableResourceRef[ ] , signal: AbortSignal) : Promise < void > {
if ( refs. length === 0 ) {
return ;
}
const resources = refs. map ( item =>
(
{
,
:
.
===
'repository'
?
this
.
_getOrCreateEntity < GitHubRepositoryRef, GitHubRepository>
(
'repository'
,
normalizeRepositoryRef
(
.
)
)
:
this
.
_getOrCreateEntity < GitHubIssueRef, GitHubIssue>
(
'issue'
,
normalizeIssueRef
(
.
)
)
,
}
)
)
.
filter
(
=>
{
const
=
.
.
.
get
(
)
.
;
return
!==
'ready'
&&
!==
'loading'
;
}
)
.
map
(
=>
(
{
...
,
:
++
.
.
}
)
)
;
if
(
.
===
0
)
{
return
;
}
const
=
[
0
]
.
.
;
if
(
.
some
(
=>
!
sameAccount
(
.
.
,
{
:
}
)
)
)
{
throw
new
GitHubRequestError
(
'GitHub hydration batch spans multiple accounts'
,
'validation'
)
;
}
const
=
new
Date
(
this
.
.
now
(
)
)
.
toISOString
(
)
;
for
(
const
{
}
of
)
{
this
.
.
cancel
(
this
.
_entityTaskKey
(
)
)
;
.
setLoading
(
)
;
}
const
:
string
[
]
=
[
]
;
const
:
string
[
]
=
[
]
;
const
:
<
string
,
unknown
>
=
{
}
;
for
(
let
=
0
;
<
.
;
++
)
{
const
=
[
]
.
;
.
push
(
` $owner ${ index} : String! `
,
` $repo ${ index} : String! `
)
;
[
` owner ${ index} `
]
=
.
.
;
[
` repo ${ index} `
]
=
.
.
;
if
(
.
===
'repository'
)
{
.
push
(
` r ${ index} : repository(owner: $owner ${ index} , name: $repo ${ index} ) { ${ repositoryHydrationFields} } `
)
;
}
else
{
.
push
(
` $number ${ index} : Int! `
)
;
[
` number ${ index} `
]
=
.
.
number
;
.
push
(
` r ${ index} : repository(owner: $owner ${ index} , name: $repo ${ index} ) { issue(number: $number ${ index} ) { ${ issueHydrationFields} } } `
)
;
}
}
const
=
` query HydrateGitHubResources( ${ definitions. join ( ', ' ) } ) { ${ selections. join ( '\n' ) } rateLimit { limit remaining used resetAt } } `
;
let
:
;
try
{
=
asObject
(
await
this
.
_graphqlRaw
(
,
,
,
)
,
'GitHub hydration response was malformed'
)
;
}
catch
(
)
{
for
(
const
{
,
}
of
)
{
if
(
.
||
.
!==
)
{
continue
;
}
.
setError
(
toFragmentError
(
)
)
;
if
(
.
.
>
0
)
{
this
.
_scheduleEntity
(
,
this
.
.
now
(
)
)
;
}
else
{
this
.
_makeEntityDormant
(
)
;
}
}
throw
;
}
const
=
new
Date
(
this
.
.
now
(
)
)
.
toISOString
(
)
;
let
=
0
;
for
(
let
=
0
;
<
.
;
++
)
{
const
{
,
,
}
=
[
]
;
if
(
.
||
.
!==
)
{
continue
;
}
const
=
optionalObjectProperty
(
,
` r ${ index} `
)
;
try
{
if
(
.
===
'repository'
)
{
if
(
!
)
{
this
.
_handleMissingHydrationResult
(
)
;
continue
;
}
const
=
toGraphQLRepository
(
)
;
const
=
this
.
_getOrCreateEntity < GitHubRepositoryRef, GitHubRepository>
(
'repository'
,
normalizeRepositoryRef
(
.
)
)
;
.
.
set
(
{
,
:
'ready'
,
:
true
,
,
:
}
,
undefined
)
;
this
.
_canonicalizeRepository
(
,
)
;
if
(
.
.
===
0
)
{
this
.
_makeEntityDormant
(
)
;
}
else
{
this
.
_scheduleEntity
(
,
this
.
.
now
(
)
+
this
.
_pollDelay
(
)
)
;
}
++
;
}
else
{
const
=
?
optionalObjectProperty
(
,
'issue'
)
:
undefined
;
if
(
!
)
{
this
.
_handleMissingHydrationResult
(
)
;
continue
;
}
const
=
toGraphQLIssue
(
)
;
const
=
this
.
_getOrCreateEntity < GitHubIssueRef, GitHubIssue>
(
'issue'
,
normalizeIssueRef
(
.
)
)
;
.
.
set
(
{
,
:
'ready'
,
:
true
,
,
:
}
,
undefined
)
;
if
(
.
.
===
0
)
{
this
.
_makeEntityDormant
(
)
;
}
else
if
(
this
.
_shouldPollEntity
(
)
)
{
this
.
_scheduleEntity
(
,
this
.
.
now
(
)
+
this
.
_pollDelay
(
)
)
;
}
++
;
}
}
catch
(
)
{
this
.
_handleHydrationError
(
,
)
;
}
}
this
.
.
trace
(
` [GitHubQueryService] Hydrated ${ hydratedCount} of ${ resources. length} resource(s) in one GraphQL request `
)
;
}
private
_handleHydrationError
(
:
<
,
>
,
:
unknown
)
:
void
{
.
.
set
(
{
...
.
.
get
(
)
,
:
'error'
,
:
false
,
:
toFragmentError
(
)
,
}
,
undefined
)
;
if
(
.
.
>
0
)
{
this
.
_scheduleEntity
(
,
this
.
.
now
(
)
)
;
}
else
{
this
.
_makeEntityDormant
(
)
;
}
}
private
_handleMissingHydrationResult
(
:
<
,
>
)
:
void
{
.
.
set
(
{
...
.
.
get
(
)
,
:
'error'
,
:
false
,
:
{
:
'notFound'
,
:
'GitHub resource was not found'
}
,
}
,
undefined
)
;
if
(
.
.
===
0
)
{
this
.
_makeEntityDormant
(
)
;
}
}
subscribeIssue
(
:
,
:
)
:
{
const
=
normalizeIssueRef
(
)
;
const
=
this
.
_getOrCreateEntity < GitHubIssueRef, GitHubIssue>
(
'issue'
,
)
;
const
=
new
EntitySubscription
(
.
as
,
,
this
,
)
;
.
.
add
(
)
;
this
.
.
trace
(
` [GitHubQueryService] Added issue subscription for ${ formatEntityRef ( entry. ref) } (entry ${ entry. id} , subscriptions: ${ entry. subscriptions. size} ) `
)
;
this
.
_activateEntity
(
)
;
return
;
}
async
compare
(
:
,
:
string
,
:
string
,
:
)
:
Promise
<
>
{
const
=
normalizeRepositoryRef
(
)
;
if
(
!
||
!
)
{
throw
new
Error
(
'GitHub comparison requires base and head refs'
)
;
}
return
this
.
_withCredential
(
,
,
async
(
,
)
=>
{
const
:
[
]
=
[
]
;
let
:
[
]
=
[
]
;
let
=
false
;
let
:
|
undefined
;
let
=
0
;
for
(
let
=
1
;
<=
;
++
)
{
const
=
await
this
.
.
rest < unknown >
(
.
,
.
,
{
:
'GET'
,
:
` ${ this . _restUrl ( normalized, ` compare/ ${ encodeURIComponent ( base) } ... ${ encodeURIComponent ( head) } ` ) } ?per_page=100&page= ${ page} `
,
:
true
,
:
'interactive'
,
}
,
)
;
const
=
asObject
(
.
,
'GitHub comparison response was malformed'
)
;
??=
;
=
numberProperty
(
,
'total_commits'
)
??
;
.
push
(
...
arrayProperty
(
,
'commits'
)
.
map
(
)
)
;
if
(
===
1
)
{
const
=
optionalArrayProperty
(
,
'files'
)
;
=
!==
undefined
;
=
(
??
[
]
)
.
map
(
)
;
}
if
(
.
>=
||
arrayProperty
(
,
'commits'
)
.
<
100
)
{
break
;
}
}
if
(
!
)
{
throw
new
GitHubRequestError
(
'GitHub comparison did not return a response'
,
'malformedResponse'
)
;
}
const
=
requiredString
(
objectProperty
(
,
'merge_base_commit'
)
,
'sha'
)
;
const
=
.
>=
;
return
{
:
requiredString
(
objectProperty
(
,
'base_commit'
)
,
'sha'
)
,
,
:
?
.
at
(
-
1
)
?.
??
:
undefined
,
:
enumProperty
(
,
'status'
,
[
'ahead'
,
'behind'
,
'diverged'
,
'identical'
]
,
'diverged'
)
,
:
numberProperty
(
,
'ahead_by'
)
??
0
,
:
numberProperty
(
,
'behind_by'
)
??
0
,
,
,
,
,
:
&&
.
<
300
,
}
;
}
)
;
}
async
listPullRequests
(
:
,
:
string
|
undefined
,
:
)
:
Promise
<
>
{
return
this
.
_graphqlWithCredential
(
,
,
{
:
.
,
:
.
,
:
??
null
,
}
,
,
=>
{
const
=
objectProperty
(
asObject
(
,
'GitHub pull request page was malformed'
)
,
'repository'
)
;
const
=
objectProperty
(
,
'pullRequests'
)
;
const
=
objectProperty
(
,
'pageInfo'
)
;
return
{
:
arrayProperty
(
,
'nodes'
)
.
map
(
=>
toPullRequestSummary
(
,
false
,
false
)
)
,
:
nullableStringProperty
(
,
'endCursor'
)
,
:
booleanProperty
(
,
'hasNextPage'
)
??
false
,
}
;
}
)
;
}
listPullRequestsWaitingForReview
(
:
,
:
)
:
Promise
<
readonly
[
]
>
{
return
this
.
_searchPullRequests
(
,
` repo: ${ ref. owner} / ${ ref. repo} is:pr is:open review-requested:@me sort:updated-desc `
,
true
,
false
,
)
;
}
listPullRequestsAssignedToViewer
(
:
,
:
)
:
Promise
<
readonly
[
]
>
{
return
this
.
_searchPullRequests
(
,
` repo: ${ ref. owner} / ${ ref. repo} is:pr is:open assignee:@me sort:updated-desc `
,
false
,
true
,
)
;
}
async
getPullRequestContext
(
:
,
:
)
:
Promise
<
>
{
const
=
normalizeRepositoryRef
(
)
;
return
this
.
_withCredential
(
,
,
async
(
,
)
=>
{
const
=
` pulls/ ${ ref. number } `
;
const
[
,
,
,
]
=
await
Promise
.
all
(
[
this
.
.
rest < unknown >
(
.
,
.
,
{
:
'GET'
,
:
this
.
_restUrl
(
,
)
,
:
true
,
:
'interactive'
,
}
,
)
,
this
.
_fetchRestPages
(
,
,
` ${ root} /files `
,
)
,
this
.
_fetchRestPages
(
,
,
` issues/ ${ ref. number } /comments `
,
)
,
this
.
_fetchRestPages
(
,
,
` ${ root} /comments `
,
)
,
]
)
;
const
=
asObject
(
.
,
'GitHub pull request context was malformed'
)
;
const
=
objectProperty
(
,
'base'
)
;
const
=
objectProperty
(
,
'head'
)
;
const
:
[
]
=
[
...
.
map
(
=>
toContextComment
(
'issue'
,
)
)
,
...
.
map
(
=>
toContextComment
(
'review'
,
)
)
,
]
.
sort
(
(
,
)
=>
.
.
localeCompare
(
.
)
||
.
.
localeCompare
(
.
)
)
;
return
{
,
:
requiredString
(
,
'html_url'
)
,
:
requiredString
(
,
'title'
)
,
:
nullableStringProperty
(
,
'body'
)
??
''
,
:
requiredString
(
objectProperty
(
,
'user'
)
,
'login'
)
,
:
booleanProperty
(
,
'draft'
)
??
false
,
:
requiredString
(
,
'ref'
)
,
:
requiredString
(
,
'ref'
)
,
:
requiredString
(
,
'ref'
)
,
:
requiredString
(
,
'updated_at'
)
,
:
createPatch
(
)
,
:
.
<
3_000
,
,
:
true
,
}
;
}
)
;
}
async
findPullRequestByHeadBranch
(
:
,
:
string
,
:
string
|
undefined
,
:
,
)
:
Promise
<
|
undefined
>
{
const
=
normalizeRepositoryRef
(
)
;
const
=
??
.
;
return
this
.
_withCredential
(
,
,
async
(
,
)
=>
{
const
=
await
this
.
.
rest < unknown >
(
.
,
.
,
{
:
'GET'
,
:
` ${ this . _restUrl ( normalized, 'pulls' ) } ?head= ${ encodeURIComponent ( ` ${ owner} : ${ branch} ` ) } &state=all&sort=updated&direction=desc&per_page=1 `
,
:
true
,
:
'interactive'
,
}
,
)
;
const
=
asArray
(
.
,
'GitHub pull request lookup response was malformed'
)
;
return
.
>
0
?
toPullRequestLookup
(
,
[
0
]
)
:
undefined
;
}
)
;
}
async
findPullRequestByHeadSha
(
:
,
:
string
,
:
)
:
Promise
<
|
undefined
>
{
const
=
normalizeRepositoryRef
(
)
;
return
this
.
_withCredential
(
,
,
async
(
,
)
=>
{
let
:
readonly
unknown
[
]
;
try
{
const
=
await
this
.
.
rest < unknown >
(
.
,
.
,
{
:
'GET'
,
:
` ${ this . _restUrl ( normalized, ` commits/ ${ encodeURIComponent ( sha) } /pulls ` ) } ?per_page= ${ maximumCommitPullRequests} `
,
:
true
,
:
'interactive'
,
}
,
)
;
=
asArray
(
.
,
'GitHub commit pull request lookup response was malformed'
)
;
}
catch
(
)
{
if
(
instanceof
GitHubRequestError
&&
.
===
422
&&
.
?.
includes
(
'No commit found for SHA'
)
)
{
return
undefined
;
}
throw
;
}
if
(
.
>=
)
{
return
undefined
;
}
const
=
.
filter
(
=>
stringProperty
(
objectProperty
(
asObject
(
,
'GitHub pull request was malformed'
)
,
'head'
)
,
'sha'
)
===
)
;
const
=
.
filter
(
=>
stringProperty
(
asObject
(
,
'GitHub pull request was malformed'
)
,
'state'
)
===
'open'
)
;
const
=
.
>
0
?
:
;
return
.
===
1
?
toPullRequestLookup
(
,
[
0
]
)
:
undefined
;
}
)
;
}
getRecentAssignedIssues
(
:
,
:
)
:
Promise
<
readonly
[
]
>
{
return
this
.
_graphqlWithCredential
(
,
,
{
:
` repo: ${ ref. owner} / ${ ref. repo} is:issue is:open assignee:@me sort:updated-desc `
,
}
,
,
=>
arrayProperty
(
objectProperty
(
asObject
(
,
'GitHub recent issues response was malformed'
)
,
'search'
)
,
'nodes'
)
.
filter
(
)
.
map
(
)
)
;
}
getRecentAuthoredPullRequests
(
:
,
:
)
:
Promise
<
readonly
[
]
>
{
return
this
.
_graphqlWithCredential
(
,
,
{
:
` repo: ${ ref. owner} / ${ ref. repo} is:pr is:open author:@me sort:updated-desc `
,
}
,
,
=>
arrayProperty
(
objectProperty
(
asObject
(
,
'GitHub recent pull requests response was malformed'
)
,
'search'
)
,
'nodes'
)
.
filter
(
)
.
map
(
)
)
;
}
async
getPullRequestReviewThreadSummary
(
:
,
:
)
:
Promise
<
readonly
[
]
>
{
const
:
[
]
=
[
]
;
let
:
string
|
undefined
;
for
(
let
=
0
;
<
;
++
)
{
const
=
await
this
.
_graphqlRaw
(
,
,
{
:
.
,
:
.
,
number
:
.
number
,
,
}
,
)
;
const
=
objectAt
(
,
'repository'
,
'pullRequest'
,
'reviewThreads'
)
;
.
push
(
...
arrayProperty
(
,
'nodes'
)
.
filter
(
)
.
map
(
)
)
;
const
=
objectProperty
(
,
'pageInfo'
)
;
if
(
!
booleanProperty
(
,
'hasNextPage'
)
)
{
return
;
}
=
requiredString
(
,
'endCursor'
)
;
}
throw
new
GitHubRequestError
(
'GitHub review-thread summary pagination exceeded its page limit'
,
'malformedResponse'
)
;
}
async
getIssuesWithLinkedPullRequests
(
:
,
:
readonly
number
[
]
,
:
,
)
:
Promise
<
readonly
number
[
]
>
{
const
=
[
...
new
Set
(
.
filter
(
number
=>
.
isInteger
(
number
)
&&
number
>
0
)
)
]
;
const
:
number
[
]
=
[
]
;
for
(
let
=
0
;
<
.
;
+=
)
{
const
=
.
slice
(
,
+
)
;
const
=
.
map
(
(
,
)
=>
` $issue ${ index} : Int! `
)
.
join
(
', '
)
;
const
=
.
map
(
(
,
)
=>
` issue ${ index} : issue(number: $issue ${ index} ) {
closedByPullRequestsReferences(first: 1, includeClosedPrs: true) { totalCount }
} `
)
.
join
(
'\n'
)
;
const
=
` query AgentHostIssueLinkage($owner: String!, $repo: String!, ${ variableDefinitions} ) {
repository(owner: $owner, name: $repo) { ${ selections} }
rateLimit { limit remaining used resetAt }
} `
;
const
:
<
string
,
string
|
number
>
=
{
:
.
,
:
.
}
;
.
forEach
(
(
number
,
)
=>
[
` issue ${ index} `
]
=
number
)
;
const
=
await
this
.
_graphqlRaw
(
,
,
,
)
;
const
=
objectProperty
(
asObject
(
,
'GitHub issue linkage response was malformed'
)
,
'repository'
)
;
.
forEach
(
(
number
,
)
=>
{
const
=
optionalObjectProperty
(
,
` issue ${ index} `
)
;
const
=
?
optionalObjectProperty
(
,
'closedByPullRequestsReferences'
)
:
undefined
;
if
(
(
?
numberProperty
(
,
'totalCount'
)
??
0
:
0
)
>
0
)
{
.
push
(
number
)
;
}
}
)
;
}
return
;
}
updateEntitySubscription
(
:
<
,
>
)
:
void
{
if
(
this
.
_shouldPollEntity
(
)
)
{
this
.
_scheduleEntity
(
,
this
.
.
now
(
)
+
this
.
_pollDelay
(
)
)
;
}
}
async
refreshEntity
(
:
<
,
>
,
:
)
:
Promise
<
void
>
{
if
(
.
||
.
.
===
0
)
{
return
;
}
this
.
.
cancel
(
this
.
_entityTaskKey
(
)
)
;
if
(
.
)
{
await
raceCancellationError
(
.
.
,
)
;
return
;
}
const
=
new
AbortController
(
)
;
.
++
;
const
:
=
{
,
:
this
.
_runEntityFetch
(
,
)
.
finally
(
(
)
=>
{
if
(
.
===
)
{
.
=
undefined
;
}
}
)
,
}
;
.
=
;
await
raceCancellationError
(
.
,
)
;
}
removeEntitySubscription
(
:
<
,
>
)
:
void
{
const
=
.
;
if
(
!
.
.
delete
(
)
)
{
return
;
}
if
(
.
.
>
0
)
{
this
.
updateEntitySubscription
(
)
;
return
;
}
this
.
_makeEntityDormant
(
)
;
}
private
_makeEntityDormant
(
:
<
,
>
)
:
void
{
.
=
this
.
.
now
(
)
;
this
.
.
trace
(
` [GitHubQueryService] ${ entry. kind} ${ formatEntityRef ( entry. ref) } became dormant (entry ${ entry. id} ) `
)
;
this
.
.
cancel
(
this
.
_entityTaskKey
(
)
)
;
.
?.
.
abort
(
new
Error
(
'GitHub resource became dormant'
)
)
;
.
=
undefined
;
this
.
.
set
(
.
,
)
;
this
.
.
schedule
(
this
.
_dormantTaskKey
(
)
,
this
.
.
now
(
)
+
this
.
.
,
(
)
=>
{
if
(
.
!==
undefined
)
{
this
.
_disposeEntity
(
)
;
}
}
)
;
this
.
_trimDormant
(
)
;
}
clear
(
)
:
void
{
for
(
const
of
[
...
this
.
]
)
{
this
.
_disposeEntity
(
)
;
}
this
.
.
clear
(
)
;
this
.
.
clear
(
)
;
}
dispose
(
)
:
void
{
this
.
clear
(
)
;
super
.
dispose
(
)
;
}
private
_getOrCreateEntity < TRef extends EntityRef, TValue extends EntityValue>
(
:
,
:
)
:
<
,
>
{
const
=
entityKey
(
,
)
;
const
=
this
.
.
get
(
)
;
if
(
)
{
return
as
<
,
>
;
}
const
=
new
EntityEntry< TRef, TValue>
(
this
.
++
,
,
)
;
.
.
add
(
)
;
this
.
.
set
(
,
as
<
,
>
)
;
this
.
.
add
(
as
<
,
>
)
;
this
.
.
debug
(
` [GitHubQueryService] Created ${ kind} resource ${ formatEntityRef ( ref) } (entry ${ entry. id} ) `
)
;
return
;
}
private
_activateEntity
(
:
<
,
>
)
:
void
{
let
=
false
;
if
(
.
!==
undefined
)
{
.
=
undefined
;
this
.
.
delete
(
.
)
;
this
.
.
cancel
(
this
.
_dormantTaskKey
(
)
)
;
=
true
;
}
const
=
.
.
get
(
)
;
if
(
.
===
'missing'
||
.
===
'stale'
||
.
===
'error'
||
&&
.
===
undefined
&&
.
!==
'ready'
)
{
this
.
_scheduleEntity
(
,
this
.
.
now
(
)
)
;
}
else
if
(
&&
this
.
_shouldPollEntity
(
)
)
{
this
.
_scheduleEntity
(
,
this
.
.
now
(
)
+
this
.
_pollDelay
(
)
)
;
}
}
private
async
_runEntityFetch
(
:
<
,
>
,
:
)
:
Promise
<
void
>
{
const
=
.
.
get
(
)
;
.
.
set
(
{
...
,
:
'loading'
,
:
false
,
:
new
Date
(
this
.
.
now
(
)
)
.
toISOString
(
)
,
:
undefined
,
}
,
undefined
)
;
let
:
|
undefined
;
const
=
this
.
.
now
(
)
;
this
.
.
trace
(
` [GitHubQueryService] Refreshing ${ entry. kind} ${ formatEntityRef ( entry. ref) } (entry ${ entry. id} ) `
)
;
try
{
=
await
this
.
.
getCredential
(
.
)
;
if
(
!
sameAccount
(
.
,
)
)
{
throw
new
GitHubRequestError
(
'GitHub resource account does not match the current credential'
,
'authentication'
)
;
}
const
=
await
this
.
.
rest < unknown >
(
.
,
.
,
{
:
'GET'
,
:
.
===
'repository'
?
this
.
_restUrl
(
.
,
''
)
:
this
.
_restUrl
(
.
,
` issues/ ${ ( entry. ref as GitHubIssueRef) . number } `
)
,
:
true
,
:
toRequestPriority
(
this
.
_effectivePriority
(
)
)
,
}
,
.
any
(
[
.
,
.
]
)
)
;
if
(
.
||
.
.
||
.
.
===
0
)
{
return
;
}
const
=
.
===
'repository'
?
toRepository
(
.
)
:
toIssue
(
.
)
;
.
.
set
(
{
,
:
'ready'
,
:
true
,
:
new
Date
(
this
.
.
now
(
)
)
.
toISOString
(
)
,
:
new
Date
(
this
.
.
now
(
)
)
.
toISOString
(
)
,
}
,
undefined
)
;
if
(
.
===
'repository'
)
{
this
.
_canonicalizeRepository
(
as
<
,
>
,
as
)
;
}
this
.
.
trace
(
` [GitHubQueryService] Refreshed ${ entry. kind} ${ formatEntityRef ( entry. ref) } in ${ this . _clock. now ( ) - startedAt} ms (entry ${ entry. id} ) `
)
;
.
=
0
;
if
(
this
.
_shouldPollEntity
(
)
)
{
this
.
_scheduleEntity
(
,
this
.
.
now
(
)
+
this
.
_pollDelay
(
)
+
this
.
.
jitter
(
this
.
.
)
)
;
}
}
catch
(
)
{
if
(
&&
sameAccount
(
.
,
)
)
{
this
.
.
handleRequestError
(
,
)
;
}
if
(
!
.
&&
!
.
.
&&
.
.
>
0
)
{
if
(
?.
.
)
{
this
.
_scheduleEntity
(
,
this
.
.
now
(
)
)
;
throw
;
}
.
.
set
(
{
...
,
:
'error'
,
:
false
,
:
new
Date
(
this
.
.
now
(
)
)
.
toISOString
(
)
,
:
toFragmentError
(
)
,
}
,
undefined
)
;
if
(
!
(
instanceof
GitHubRequestError
)
||
.
!==
'authentication'
)
{
this
.
_scheduleAfterFailure
(
)
;
}
}
this
.
.
debug
(
` [GitHubQueryService] Refresh ${ entry. kind} ${ formatEntityRef ( entry. ref) } ${ controller. signal. aborted ? 'cancelled' : 'failed' } after ${ this . _clock. now ( ) - startedAt} ms ( ${ queryErrorKind ( error) } ) `
)
;
throw
;
}
}
private
async
_searchPullRequests
(
:
,
:
string
,
:
boolean
,
:
boolean
,
:
,
)
:
Promise
<
readonly
[
]
>
{
return
this
.
_graphqlWithCredential
(
,
,
{
}
,
,
=>
arrayProperty
(
objectProperty
(
asObject
(
,
'GitHub pull request search response was malformed'
)
,
'search'
)
,
'nodes'
)
.
filter
(
)
.
map
(
=>
toPullRequestSummary
(
,
,
)
)
)
;
}
private
async
_graphqlRaw
(
:
,
:
string
,
:
<
<
string
,
unknown
>>
,
:
,
)
:
Promise
<
unknown
>
{
return
this
.
_withCredential
(
,
,
async
(
,
)
=>
{
const
=
await
this
.
.
getCapabilities
(
,
undefined
,
)
;
if
(
!
.
)
{
throw
new
GitHubRequestError
(
'GitHub GraphQL is unavailable on this host'
,
'schema'
)
;
}
const
=
` ${ credential. account. host. toLowerCase ( ) } \x00 ${ query} `
;
if
(
this
.
.
has
(
)
)
{
throw
new
GitHubRequestError
(
'GitHub GraphQL query is unsupported on this host'
,
'schema'
)
;
}
try
{
const
=
await
this
.
.
graphql < unknown >
(
.
,
.
,
this
.
.
getGraphQlUri
(
)
,
,
,
,
'interactive'
,
)
;
throwGraphQLErrors
(
.
)
;
return
.
;
}
catch
(
)
{
if
(
instanceof
GitHubRequestError
&&
.
===
'schema'
)
{
this
.
.
add
(
)
;
}
throw
;
}
}
)
;
}
private
async
_graphqlWithCredential < T >
(
:
,
:
string
,
:
<
<
string
,
unknown
>>
,
:
,
map
:
(
:
unknown
)
=>
T
,
)
:
Promise
<
T
>
{
return
map
(
await
this
.
_graphqlRaw
(
,
,
,
)
)
;
}
private
async
_fetchRestPages
(
:
,
:
,
:
string
,
:
,
)
:
Promise
<
readonly
unknown
[
]
>
{
const
:
unknown
[
]
=
[
]
;
let
:
string
|
undefined
=
` ${ this . _restUrl ( ref, route) } ?per_page=100&page=1 `
;
for
(
let
=
0
;
&&
<
;
++
)
{
const
=
await
this
.
.
rest < unknown >
(
.
,
.
,
{
:
'GET'
,
,
:
true
,
:
'interactive'
,
}
,
)
;
const
=
asArray
(
.
,
'GitHub paginated response was not an array'
)
;
.
push
(
...
)
;
=
nextLink
(
.
)
;
if
(
!
&&
.
===
100
)
{
=
` ${ this . _restUrl ( ref, route) } ?per_page=100&page= ${ page + 2 } `
;
}
if
(
.
<
100
)
{
=
undefined
;
}
}
if
(
)
{
throw
new
GitHubRequestError
(
'GitHub pagination exceeded its page limit'
,
'malformedResponse'
)
;
}
return
;
}
private
async
_withCredential < T >
(
:
,
:
,
task
:
(
:
,
:
)
=>
Promise
<
T
>
,
)
:
Promise
<
T
>
{
const
=
await
this
.
.
getCredential
(
)
;
if
(
!
sameAccount
(
,
)
)
{
throw
new
GitHubRequestError
(
'GitHub query account does not match the current credential'
,
'authentication'
)
;
}
try
{
return
await
task
(
,
.
any
(
[
,
.
]
)
)
;
}
catch
(
)
{
this
.
.
handleRequestError
(
,
)
;
throw
;
}
}
private
_canonicalizeRepository
(
:
<
,
>
,
:
)
:
void
{
const
[
,
,
]
=
.
.
split
(
'/'
)
;
if
(
!
||
!
||
)
{
return
;
}
.
=
{
...
.
,
,
}
;
const
=
entityKey
(
'repository'
,
.
)
;
if
(
!
this
.
.
has
(
)
)
{
this
.
.
set
(
,
as
<
,
>
)
;
.
.
add
(
)
;
this
.
.
debug
(
` [GitHubQueryService] Canonicalized repository ${ formatEntityRef ( entry. ref) } (entry ${ entry. id} , aliases: ${ entry. keys. size} ) `
)
;
}
}
private
_handleCredentialInvalidation
(
:
)
:
void
{
this
.
.
debug
(
` [GitHubQueryService] Handling credential invalidation ( ${ event. reason} ) for ${ this . _entries. size} resource(s) `
)
;
for
(
const
of
[
...
this
.
]
)
{
if
(
!
.
||
sameAccount
(
.
,
.
)
)
{
if
(
.
===
'replacement'
||
.
===
'authentication'
)
{
const
=
.
.
get
(
)
;
.
.
set
(
{
...
,
:
.
?
'stale'
:
'missing'
,
:
false
,
:
undefined
,
}
,
undefined
)
;
if
(
.
.
>
0
)
{
this
.
_scheduleEntity
(
,
this
.
.
now
(
)
)
;
}
}
else
{
this
.
_disposeEntity
(
)
;
}
}
}
}
private
_disposeEntity
(
:
<
,
>
)
:
void
{
if
(
.
)
{
return
;
}
.
=
true
;
this
.
.
trace
(
` [GitHubQueryService] Disposing ${ entry. kind} ${ formatEntityRef ( entry. ref) } (entry ${ entry. id} ) `
)
;
.
?.
.
abort
(
new
Error
(
'GitHub resource was disposed'
)
)
;
this
.
.
cancel
(
this
.
_entityTaskKey
(
)
)
;
this
.
.
cancel
(
this
.
_dormantTaskKey
(
)
)
;
for
(
const
of
.
)
{
if
(
this
.
.
get
(
)
===
)
{
this
.
.
delete
(
)
;
}
}
.
.
clear
(
)
;
this
.
.
delete
(
.
)
;
this
.
.
delete
(
)
;
}
private
_trimDormant
(
)
:
void
{
while
(
this
.
.
>
this
.
.
)
{
const
=
[
...
this
.
.
values
(
)
]
.
sort
(
(
,
)
=>
(
.
??
0
)
-
(
.
??
0
)
||
.
-
.
)
[
0
]
;
this
.
_disposeEntity
(
)
;
}
}
private
_scheduleEntity
(
:
<
,
>
,
:
number
)
:
void
{
if
(
.
||
.
.
===
0
)
{
return
;
}
this
.
.
schedule
(
this
.
_entityTaskKey
(
)
,
,
(
)
=>
{
void
this
.
refreshEntity
(
,
.
)
.
catch
(
=>
{
if
(
!
.
&&
.
.
>
0
)
{
this
.
.
warn
(
` [GitHubQueryService] Failed to refresh ${ entry. kind} ${ entry. ref. owner} / ${ entry. ref. repo} `
,
)
;
}
}
)
;
}
)
;
}
private
_effectivePriority
(
:
<
,
>
)
:
{
let
:
=
'background'
;
for
(
const
of
.
)
{
if
(
.
.
===
'interactive'
)
{
return
'interactive'
;
}
if
(
.
.
===
'visible'
)
{
=
'visible'
;
}
}
return
;
}
private
_pollDelay
(
:
<
,
>
)
:
number
{
return
this
.
_effectivePriority
(
)
===
'background'
?
this
.
.
:
this
.
.
;
}
private
_scheduleAfterFailure
(
:
<
,
>
)
:
void
{
.
++
;
const
=
gitHubBackoffDelay
(
this
.
.
,
this
.
,
.
,
this
.
_pollDelay
(
)
)
;
this
.
_scheduleEntity
(
,
this
.
.
now
(
)
+
)
;
}
private
_shouldPollEntity
(
:
<
,
>
)
:
boolean
{
if
(
.
===
'repository'
)
{
return
true
;
}
const
=
.
.
get
(
)
;
return
.
!==
'ready'
||
(
.
as
|
undefined
)
?.
===
'open'
;
}
private
_entityTaskKey
(
:
<
,
>
)
:
string
{
return
` entity\x00 ${ entry. id} `
;
}
private
_dormantTaskKey
(
:
<
,
>
)
:
string
{
return
` entity-dormant\x00 ${ entry. id} `
;
}
private
_restUrl
(
:
,
:
string
)
:
string
{
const
=
?
` / ${ route} `
:
''
;
return
` ${ this . _endpoint. getApiBaseUri ( ) } /repos/ ${ encodeURIComponent ( ref. owner) } / ${ encodeURIComponent ( ref. repo) } ${ suffix} `
;
}
}
function
normalizeRepositoryRef
(
:
)
:
{
const
=
.
.
trim
(
)
.
toLowerCase
(
)
;
const
=
.
.
trim
(
)
;
const
=
.
.
trim
(
)
;
const
=
.
.
trim
(
)
;
if
(
!
||
!
||
!
||
!
)
{
throw
new
Error
(
'GitHub repository reference is incomplete'
)
;
}
return
{
,
,
,
}
;
}
function
normalizeIssueRef
(
:
)
:
{
const
=
normalizeRepositoryRef
(
)
;
if
(
!
.
isInteger
(
.
number
)
||
.
number
<=
0
)
{
throw
new
Error
(
'GitHub issue reference requires a positive number'
)
;
}
return
{
...
,
number
:
.
number
}
;
}
function
entityKey
(
:
,
:
)
:
string
{
return
[
,
.
.
toLowerCase
(
)
,
.
,
.
.
toLowerCase
(
)
,
.
.
toLowerCase
(
)
,
hasKey
(
,
{
number
:
true
}
)
?
.
number
:
''
,
]
.
join
(
'\x00'
)
;
}
function
sameAccount
(
:
,
:
{
readonly
:
{
readonly
:
string
;
readonly
:
string
}
}
,
)
:
boolean
{
return
.
.
toLowerCase
(
)
===
.
.
.
toLowerCase
(
)
&&
.
===
.
.
;
}
function
toRequestPriority
(
:
)
:
'interactive'
|
'visible'
|
'background'
{
return
;
}
function
toRepository
(
:
unknown
)
:
{
const
=
asObject
(
,
'GitHub repository response was malformed'
)
;
const
=
objectProperty
(
,
'owner'
)
;
const
=
nullableStringProperty
(
,
'language'
)
;
const
=
numberProperty
(
,
'stargazers_count'
)
;
return
{
:
idProperty
(
,
'node_id'
)
??
idProperty
(
,
'id'
)
,
:
requiredActor
(
)
,
:
requiredString
(
,
'name'
)
,
:
requiredString
(
,
'full_name'
)
,
...
(
!==
undefined
?
{
}
:
{
}
)
,
...
(
!==
undefined
?
{
}
:
{
}
)
,
:
requiredString
(
,
'default_branch'
)
,
private
:
booleanProperty
(
,
'private'
)
??
false
,
:
nullableStringProperty
(
,
'description'
)
??
''
,
:
requiredString
(
,
'html_url'
)
,
:
booleanProperty
(
,
'archived'
)
??
false
,
:
booleanProperty
(
,
'fork'
)
??
false
,
}
;
}
function
toGraphQLRepository
(
:
)
:
{
const
=
objectProperty
(
,
'owner'
)
;
const
=
optionalObjectProperty
(
,
'primaryLanguage'
)
;
const
=
optionalObjectProperty
(
,
'defaultBranchRef'
)
;
const
=
numberProperty
(
,
'stargazerCount'
)
;
return
{
:
idProperty
(
,
'id'
)
,
:
requiredActor
(
)
,
:
requiredString
(
,
'name'
)
,
:
requiredString
(
,
'nameWithOwner'
)
,
...
(
?
{
:
requiredString
(
,
'name'
)
}
:
{
}
)
,
...
(
!==
undefined
?
{
}
:
{
}
)
,
:
?
requiredString
(
,
'name'
)
:
''
,
private
:
booleanProperty
(
,
'isPrivate'
)
??
false
,
:
nullableStringProperty
(
,
'description'
)
??
''
,
:
requiredString
(
,
'url'
)
,
:
booleanProperty
(
,
'isArchived'
)
??
false
,
:
booleanProperty
(
,
'isFork'
)
??
false
,
}
;
}
function
toGraphQLIssue
(
:
)
:
{
const
=
optionalObjectProperty
(
,
'author'
)
;
const
=
objectProperty
(
,
'assignees'
)
;
const
=
objectProperty
(
,
'labels'
)
;
const
=
nullableStringProperty
(
,
'stateReason'
)
?.
toLowerCase
(
)
;
return
{
:
idProperty
(
,
'id'
)
,
number
:
requiredNumber
(
,
'number'
)
,
:
requiredString
(
,
'title'
)
,
:
nullableStringProperty
(
,
'body'
)
??
''
,
:
requiredString
(
,
'url'
)
,
:
requiredString
(
,
'state'
)
===
'CLOSED'
?
'closed'
:
'open'
,
:
===
'completed'
||
===
'not_planned'
||
===
'duplicate'
||
===
'reopened'
?
:
undefined
,
:
?
requiredActor
(
)
:
{
:
'ghost'
}
,
:
arrayProperty
(
,
'nodes'
)
.
filter
(
)
.
map
(
)
,
:
arrayProperty
(
,
'nodes'
)
.
filter
(
)
.
map
(
=>
requiredString
(
,
'name'
)
)
,
:
requiredString
(
,
'createdAt'
)
,
:
requiredString
(
,
'updatedAt'
)
,
:
nullableStringProperty
(
,
'closedAt'
)
,
}
;
}
function
toIssue
(
:
unknown
)
:
{
const
=
asObject
(
,
'GitHub issue response was malformed'
)
;
if
(
.
has
(
,
'pull_request'
)
)
{
throw
new
GitHubRequestError
(
'Requested GitHub issue is a pull request'
,
'validation'
)
;
}
const
=
optionalObjectProperty
(
,
'user'
)
;
return
{
:
idProperty
(
,
'node_id'
)
??
idProperty
(
,
'id'
)
,
number
:
requiredNumber
(
,
'number'
)
,
:
requiredString
(
,
'title'
)
,
:
nullableStringProperty
(
,
'body'
)
??
''
,
:
requiredString
(
,
'html_url'
)
,
:
stringProperty
(
,
'state'
)
===
'closed'
?
'closed'
:
'open'
,
:
enumProperty
(
,
'state_reason'
,
[
'completed'
,
'not_planned'
,
'duplicate'
,
'reopened'
]
,
undefined
)
,
:
?
requiredActor
(
)
:
{
:
'ghost'
}
,
:
arrayProperty
(
,
'assignees'
)
.
filter
(
)
.
map
(
)
,
:
arrayProperty
(
,
'labels'
)
.
flatMap
(
=>
{
if
(
typeof
===
'string'
)
{
return
[
]
;
}
if
(
isObject
(
)
)
{
const
=
stringProperty
(
,
'name'
)
;
return
?
[
]
:
[
]
;
}
return
[
]
;
}
)
,
:
requiredString
(
,
'created_at'
)
,
:
requiredString
(
,
'updated_at'
)
,
:
nullableStringProperty
(
,
'closed_at'
)
,
}
;
}
function
toChangedFile
(
:
unknown
)
:
{
const
=
asObject
(
,
'GitHub changed file was malformed'
)
;
return
{
:
requiredString
(
,
'filename'
)
,
:
stringProperty
(
,
'previous_filename'
)
,
:
enumProperty
(
,
'status'
,
[
'added'
,
'removed'
,
'modified'
,
'renamed'
,
'copied'
,
'changed'
,
'unchanged'
]
,
'changed'
)
,
:
numberProperty
(
,
'additions'
)
??
0
,
:
numberProperty
(
,
'deletions'
)
??
0
,
:
numberProperty
(
,
'changes'
)
??
0
,
:
stringProperty
(
,
'patch'
)
,
:
stringProperty
(
,
'blob_url'
)
,
}
;
}
function
toComparisonCommit
(
:
unknown
)
:
{
const
=
asObject
(
,
'GitHub comparison commit was malformed'
)
;
const
=
objectProperty
(
,
'commit'
)
;
const
=
optionalObjectProperty
(
,
'author'
)
;
return
{
:
requiredString
(
,
'sha'
)
,
:
requiredString
(
,
'message'
)
,
:
?
requiredActor
(
)
:
undefined
,
:
optionalObjectProperty
(
,
'committer'
)
?
stringProperty
(
objectProperty
(
,
'committer'
)
,
'date'
)
:
undefined
,
:
stringProperty
(
,
'html_url'
)
,
}
;
}
function
toPullRequestSummary
(
:
unknown
,
:
boolean
,
:
boolean
)
:
{
const
=
asObject
(
,
'GitHub pull request summary was malformed'
)
;
const
number
=
requiredNumber
(
,
'number'
)
;
const
=
optionalObjectProperty
(
,
'author'
)
;
return
{
number
,
:
requiredString
(
,
'title'
)
,
:
?
requiredActor
(
)
:
{
:
'ghost'
}
,
:
requiredString
(
,
'headRefName'
)
,
:
` refs/pull/ ${ number } /head `
,
:
booleanProperty
(
,
'isDraft'
)
??
false
,
:
requiredString
(
,
'updatedAt'
)
,
:
numberProperty
(
,
'additions'
)
??
0
,
:
numberProperty
(
,
'deletions'
)
??
0
,
:
,
:
,
}
;
}
function
toPullRequestLookup
(
:
,
:
unknown
)
:
{
const
=
asObject
(
,
'GitHub pull request lookup response was malformed'
)
;
return
{
:
{
...
,
number
:
requiredNumber
(
,
'number'
)
}
,
:
idProperty
(
,
'node_id'
)
,
:
requiredString
(
,
'html_url'
)
,
:
stringProperty
(
,
'created_at'
)
,
}
;
}
function
toContextComment
(
:
'issue'
|
'review'
,
:
unknown
)
:
{
const
=
asObject
(
,
'GitHub pull request context comment was malformed'
)
;
return
{
,
:
requiredString
(
objectProperty
(
,
'user'
)
,
'login'
)
,
:
requiredString
(
,
'body'
)
,
:
requiredString
(
,
'created_at'
)
,
:
requiredString
(
,
'updated_at'
)
,
:
===
'review'
?
stringProperty
(
,
'path'
)
:
undefined
,
:
===
'review'
?
numberProperty
(
,
'line'
)
??
numberProperty
(
,
'original_line'
)
:
undefined
,
}
;
}
function
createPatch
(
:
readonly
unknown
[
]
)
:
string
{
return
.
map
(
=>
{
const
=
asObject
(
,
'GitHub pull request file was malformed'
)
;
return
[
` diff --git a/ ${ requiredString ( file, 'filename' ) } b/ ${ requiredString ( file, 'filename' ) } `
,
stringProperty
(
,
'patch'
)
??
` [Patch unavailable: ${ stringProperty ( file, 'status' ) ?? 'changed' } , + ${ numberProperty ( file, 'additions' ) ?? 0 } - ${ numberProperty ( file, 'deletions' ) ?? 0 } ] `
,
]
.
join
(
'\n'
)
;
}
)
.
join
(
'\n\n'
)
;
}
function
toRecentIssue
(
:
)
:
{
return
{
number
:
requiredNumber
(
,
'number'
)
,
:
requiredString
(
,
'title'
)
,
:
requiredString
(
,
'url'
)
,
:
requiredString
(
,
'updatedAt'
)
,
}
;
}
function
toRecentPullRequest
(
:
)
:
{
const
=
objectProperty
(
,
'commits'
)
;
const
=
arrayProperty
(
,
'nodes'
)
.
find
(
)
;
const
=
?
optionalObjectProperty
(
,
'commit'
)
:
undefined
;
const
=
?
optionalObjectProperty
(
,
'statusCheckRollup'
)
:
undefined
;
return
{
number
:
requiredNumber
(
,
'number'
)
,
:
requiredString
(
,
'title'
)
,
:
requiredString
(
,
'url'
)
,
:
requiredString
(
,
'updatedAt'
)
,
:
?
stringProperty
(
,
'state'
)
:
undefined
,
:
?
stringProperty
(
,
'committedDate'
)
:
undefined
,
}
;
}
function
toReviewThreadSummary
(
:
)
:
{
const
=
objectProperty
(
,
'comments'
)
;
const
=
arrayProperty
(
,
'nodes'
)
.
find
(
)
;
return
{
:
booleanProperty
(
,
'isResolved'
)
??
false
,
:
?
stringProperty
(
,
'createdAt'
)
:
undefined
,
}
;
}
function
throwGraphQLErrors
(
:
readonly
[
]
)
:
void
{
if
(
.
===
0
)
{
return
;
}
const
=
.
map
(
=>
.
?.
toUpperCase
(
)
)
;
const
=
.
map
(
=>
.
?.
?.
toUpperCase
(
)
)
;
const
=
.
includes
(
'RATE_LIMITED'
)
?
'rateLimit'
:
.
some
(
=>
===
'FORBIDDEN'
||
===
'UNAUTHORIZED'
)
?
'authorization'
:
.
some
(
=>
?.
includes
(
'NOT_FOUND'
)
)
?
'notFound'
:
.
some
(
=>
?.
includes
(
'VALIDATION'
)
)
?
'schema'
:
.
some
(
=>
===
'UNDEFINEDFIELD'
||
===
'ARGUMENTNOTACCEPTED'
||
===
'VARIABLEMISMATCH'
)
?
'schema'
:
'server'
;
throw
new
GitHubRequestError
(
` GitHub GraphQL query failed: ${ errors. map ( error => error. message ?? error. type ?? 'unknown error' ) . join ( '; ' ) } `
,
,
200
,
undefined
,
,
)
;
}
function
nextLink
(
:
string
|
undefined
)
:
string
|
undefined
{
if
(
!
)
{
return
undefined
;
}
for
(
const
of
.
split
(
','
)
)
{
const
=
/ ^ \s * <(?<url > [ ^ >] + ) >\s * ;\s * rel="(?<rel > [ ^ "] + ) "/
.
exec
(
)
;
if
(
?.
?.
.
split
(
/ \s + /
)
.
includes
(
'next'
)
)
{
return
.
.
;
}
}
return
undefined
;
}
function
objectAt
(
:
unknown
,
...
:
readonly
string
[
]
)
:
{
let
=
asObject
(
,
'GitHub response was malformed'
)
;
for
(
const
of
)
{
=
objectProperty
(
,
)
;
}
return
;
}
function
asObject
(
:
unknown
,
:
string
)
:
{
if
(
!
isObject
(
)
)
{
throw
new
GitHubRequestError
(
,
'malformedResponse'
)
;
}
return
;
}
function
isObject
(
:
unknown
)
:
is
{
return
Boolean
(
)
&&
typeof
===
'object'
&&
!
Array
.
isArray
(
)
;
}
function
asArray
(
:
unknown
,
:
string
)
:
readonly
unknown
[
]
{
if
(
!
Array
.
isArray
(
)
)
{
throw
new
GitHubRequestError
(
,
'malformedResponse'
)
;
}
return
;
}
function
objectProperty
(
:
,
:
string
)
:
{
return
asObject
(
.
get
(
,
)
,
` GitHub response property ${ key} was malformed `
)
;
}
function
optionalObjectProperty
(
:
,
:
string
)
:
|
undefined
{
const
=
.
get
(
,
)
;
return
===
null
||
===
undefined
?
undefined
:
asObject
(
,
` GitHub response property ${ key} was malformed `
)
;
}
function
arrayProperty
(
:
,
:
string
)
:
readonly
unknown
[
]
{
return
asArray
(
.
get
(
,
)
,
` GitHub response property ${ key} was not an array `
)
;
}
function
optionalArrayProperty
(
:
,
:
string
)
:
readonly
unknown
[
]
|
undefined
{
const
=
.
get
(
,
)
;
return
===
null
||
===
undefined
?
undefined
:
asArray
(
,
` GitHub response property ${ key} was not an array `
)
;
}
function
requiredString
(
:
,
:
string
)
:
string
{
const
=
stringProperty
(
,
)
;
if
(
===
undefined
)
{
throw
new
GitHubRequestError
(
` GitHub response property ${ key} was not a string `
,
'malformedResponse'
)
;
}
return
;
}
function
stringProperty
(
:
,
:
string
)
:
string
|
undefined
{
const
=
.
get
(
,
)
;
return
typeof
===
'string'
?
:
undefined
;
}
function
nullableStringProperty
(
:
,
:
string
)
:
string
|
undefined
{
const
=
.
get
(
,
)
;
return
===
null
?
undefined
:
typeof
===
'string'
?
:
undefined
;
}
function
numberProperty
(
:
,
:
string
)
:
number
|
undefined
{
const
=
.
get
(
,
)
;
return
typeof
===
'number'
&&
.
isFinite
(
)
?
:
undefined
;
}
function
requiredNumber
(
:
,
:
string
)
:
number
{
const
=
numberProperty
(
,
)
;
if
(
===
undefined
)
{
throw
new
GitHubRequestError
(
` GitHub response property ${ key} was not a number `
,
'malformedResponse'
)
;
}
return
;
}
function
booleanProperty
(
:
,
:
string
)
:
boolean
|
undefined
{
const
=
.
get
(
,
)
;
return
typeof
===
'boolean'
?
:
undefined
;
}
function
idProperty
(
:
,
:
string
)
:
string
|
undefined
{
const
=
.
get
(
,
)
;
return
typeof
===
'string'
||
typeof
===
'number'
?
String
(
)
:
undefined
;
}
function
enumProperty < T extends string >
(
:
,
:
string
,
:
readonly
T
[
]
,
:
T
)
:
T
;
function
enumProperty < T extends string >
(
:
,
:
string
,
:
readonly
T
[
]
,
:
undefined
)
:
T
|
undefined
;
function
enumProperty < T extends string >
(
:
,
:
string
,
:
readonly
T
[
]
,
:
T
|
undefined
)
:
T
|
undefined
{
const
=
stringProperty
(
,
)
;
return
&&
.
includes
(
as
T
)
?
as
T
:
;
}
function
requiredActor
(
:
)
:
{
const
=
requiredString
(
,
'login'
)
;
const
=
idProperty
(
,
'databaseId'
)
??
idProperty
(
,
'id'
)
;
return
?
{
,
}
:
{
}
;
}
function
toFragmentError
(
:
unknown
)
:
{
readonly
:
string
;
readonly
:
import
(
'./githubTypes.js'
)
.
;
readonly
?
:
number
}
{
if
(
instanceof
GitHubRequestError
)
{
return
{
:
.
,
:
.
,
:
.
}
;
}
return
{
:
instanceof
Error
?
.
:
String
(
)
,
:
'unknown'
}
;
}
function
formatEntityRef
(
:
)
:
string
{
return
` ${ ref. host} / ${ ref. owner} / ${ ref. repo} ${ hasKey ( ref, { number : true } ) ? ` # ${ ref. number } ` : '' } `
;
}
function
queryErrorKind
(
:
unknown
)
:
string
{
if
(
instanceof
GitHubRequestError
)
{
return
` ${ error. kind} ${ error. statusCode === undefined ? '' : ` : ${ error. statusCode} ` } `
;
}
return
instanceof
Error
?
.
:
typeof
;
}