ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / .github / skills / azure-pipelines / azure-pipeline.ts 1886 строк · изменён 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
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
import { spawn, execSync } from 'child_process' ;
import fs from 'fs' ;
import path from 'path' ;
import os from 'os' ;
const ORGANIZATION = 'https://dev.azure.com/monacotools' ;
const PROJECT = 'Monaco' ;
const DEFAULT_DEFINITION_ID = '111' ;
const
id
buildNumber
status
result
sourceBranch
reason
startTime
finishTime
requestedBy displayName
requestedFor displayName
id
parentId
type
name
state
result
order
log id
records TimelineRecord
name
resource
downloadUrl
properties artifactsize
branch
definitionId
parameters
dryRun
help
buildId
branch
reason
definitionId
watch
watchInterval
downloadLog
downloadArtifact
jsonOutput
help
buildId
definitionId
dryRun
help
colors
text
text
text
text
text
text
value name
value
value length
colors
process
value
colors
process
value
value
value length
colors
process
value
colors
process
values
values length
parameter values
parameter length
colors
process
parameter
colors
process
value
value
value length
colors
process
value
colors
process
value value value value
colors
process
value
value value
colors
process
command
stdio
stdio
encoding stdio
colors
process
colors
stdio
colors
process
seconds
resolve resolve seconds
process stdout
status
status
colors
colors
colors
colors status
status
result
result
colors
colors
colors
colors
result
state result
state
result
colors
result
colors
result
colors
colors
state
colors
colors
bytes
bytes
k
sizes
i Math Math bytes Math k
bytes Math k i sizes i
dateStr
dateStr
date dateStr
now
diffMs now date
diffMins Math diffMs
diffHours Math diffMs
diffDays Math diffMs
diffMins
diffMins
diffHours
reason
reason
reason
str width
str length width
str width
str width
build Build
id build id
buildNumber build buildNumber
status build status
result build result
sourceBranch build sourceBranch
startTime build startTime
finishTime build finishTime
requestedBy build requestedBy displayName
colors
requestedBy
startTime
finishTime
builds Build
colors
colors
builds builds length
colors
build builds
id build id
branch build sourceBranch
requestedBy build requestedBy displayName build requestedFor displayName
reason build reason
started build startTime
statusStr
build status
build result
statusStr colors
statusStr colors
statusStr colors
statusStr colors
statusStr colors build result
build status
statusStr colors
build status
statusStr colors
build status
statusStr colors
statusStr colors build status
colors
timeline Timeline
colors
timeline timeline records
colors
records timeline records
stages records r r type
phases records r r type
jobs records r r type
phaseToStage
phase phases
phase parentId
phaseToStage phase id phase parentId
stages a b a order b order
stage stages
status stage state stage result
name stage name
stagePhaseIds phases p p parentId stage id p p id
stageJobs jobs j j parentId stagePhaseIds j parentId
stageJobs a b a order b order
job stageJobs
jobStatus job state job result
jobName job name
logId job log id
logInfo logId colors
artifacts Artifact
colors
artifacts artifacts length
colors
artifact artifacts
name artifact name
size artifact resource properties artifactsize
size size
sizeStr
buildId
colors
colors
colors
organization
project
organization project
organization organization
project project
args
resolve reject
azBin process platform
proc azBin args shell
stdout
stderr
proc stdout data Buffer
stdout data
proc stderr data Buffer
stderr data
proc code
code
stdout
stderr stdout
proc reject
method url body
args
method
url
body
tmpDir os
bodyFile path tmpDir
fs bodyFile body
args
args
result args
result
fs bodyFile
result args
result
definitionId branch parameters Build
args
organization
project
definitionId
branch
parameters length
args parameters
args
result args
result
buildId Build
args
organization
project
buildId
result args
result
definitionId options branch reason top Build
args
organization
project
definitionId
options top
options branch
args options branch
options reason
args options reason
result args
result
branch definitionId
args
organization
project
definitionId
branch
result args
result
buildId Build
url
url status
buildId Timeline
url
url
buildId Artifact
url
response url
response value
buildId logId
url
args url
content args
tmpDir os
outputPath path tmpDir
colors
colors
fs outputPath content
outputPath
buildId artifactName
artifacts buildId
artifact artifacts a a name artifactName
artifact
available artifacts a a name
downloadUrl artifact resource downloadUrl
downloadUrl
tmpDir os
outputPath path tmpDir
colors
colors
tokenArgs
token tokenArgs
response downloadUrl
headers
redirect
response ok
buffer Buffer response
fs outputPath buffer
outputPath
scriptName
args QueueArgs
result QueueArgs
branch
definitionId
parameters
dryRun
help
i i args length i
arg args i
arg
result branch args i
result definitionId args i
parameter args i
parameter
result parameters parameter
result parameters args i v v length
result dryRun
result help
colors
process
result
args QueueArgs
args definitionId
args branch
args parameters
args
parsedArgs args
parsedArgs help
process
parsedArgs
branch parsedArgs branch
branch
branch
branch
colors
process
branch
colors
parsedArgs parameters length
parsedArgs dryRun
colors
cmdArgs
parsedArgs definitionId
branch
parsedArgs parameters length
cmdArgs parsedArgs parameters
cmdArgs
displayArgs cmdArgs a a a
process
colors
client
data client parsedArgs definitionId branch parsedArgs parameters
buildId data id
buildNumber data buildNumber
buildUrl
colors
buildNumber
e
error e e e
colors
error message
process
scriptName
args StatusArgs
result StatusArgs
buildId
branch
reason
definitionId
watch
watchInterval
downloadLog
downloadArtifact
jsonOutput
help
i i args length i
arg args i
arg
result buildId args i
result branch args i
result reason args i
result definitionId args i
result watch
args i args i
result watchInterval args i
result downloadLog args i
result downloadArtifact args i
result jsonOutput
result help
colors
process
result
args StatusArgs
args buildId
args definitionId
args downloadLog
args downloadArtifact
args watch
args watchInterval
args
parsedArgs args
parsedArgs help
process
parsedArgs
client
buildId parsedArgs buildId
buildId parsedArgs downloadLog parsedArgs downloadArtifact parsedArgs watch
builds client parsedArgs definitionId
branch parsedArgs branch
reason parsedArgs reason
top
parsedArgs jsonOutput
builds
filters
parsedArgs branch
filters
parsedArgs reason
filters
filters length
colors
builds
buildId
branch
branch
colors
process
colors
buildId client branch parsedArgs definitionId
buildId
colors
process
parsedArgs downloadLog
outputPath client buildId parsedArgs downloadLog
colors
e
colors e Error message
process
parsedArgs downloadArtifact
outputPath client buildId parsedArgs downloadArtifact
colors
e
colors e Error message
process
parsedArgs watch
colors
build client buildId
build
colors
process
parsedArgs jsonOutput
build
build
timeline client buildId
timeline
artifacts client buildId
artifacts
buildId
build status
colors
process
colors
parsedArgs watchInterval
build client buildId
build
colors
process
parsedArgs jsonOutput
build
build
timeline client buildId
timeline
artifacts client buildId
artifacts
buildId
scriptName
args CancelArgs
result CancelArgs
buildId
definitionId
dryRun
help
i i args length i
arg args i
arg
result buildId args i
result definitionId args i
result dryRun
result help
colors
process
result
args CancelArgs
args buildId
args definitionId
args
parsedArgs args
parsedArgs help
process
parsedArgs
buildId parsedArgs buildId
buildId
colors
process
client
build client buildId
build
colors
process
buildUrl
colors
build status
colors
process
build status
colors
process
parsedArgs dryRun
colors
process
colors
client buildId
colors
e
error e e e
colors
error message
process
capturedCommands
mockResponses Map
organization project
organization project
commandPattern response
mockResponses commandPattern response
override args
capturedCommands args
commandKey args
pattern response mockResponses
commandKey pattern
response
args args
id buildNumber
args args args
id
buildNumber
status
sourceBranch
args args args
id buildNumber status result
args args
id status
args args
records
args args
value
describe it
assert
args
assert args branch
args
assert args definitionId
args
assert args parameters
args
assert args parameters
args
assert args dryRun
args
assert args branch
assert args definitionId
assert args parameters
assert args dryRun
args
assert args buildId
args
assert args branch
args
assert args watch
assert args watchInterval
args
assert args watch
assert args watchInterval
args
assert args downloadLog
args
assert args downloadArtifact
args
assert args jsonOutput
args
assert args buildId
args
assert args dryRun
client
client
assert client capturedCommands length
cmd client capturedCommands
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
client
client
cmd client capturedCommands
assert cmd
assert cmd
assert cmd
client
client
cmd client capturedCommands
assert cmd
assert cmd cmd
client
client
assert client capturedCommands length
cmd client capturedCommands
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
client
client
assert client capturedCommands length
cmd client capturedCommands
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
client
client branch
cmd client capturedCommands
assert cmd
assert cmd
client
client reason
cmd client capturedCommands
assert cmd
assert cmd
client
client top
cmd client capturedCommands
assert cmd
assert cmd
client
client
cmd client capturedCommands
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
client
client
cmd client capturedCommands
assert cmd
assert cmd
assert cmd
assert cmd
client
client
cmd client capturedCommands
assert cmd
assert cmd
assert cmd
assert cmd
client
client
cmd client capturedCommands
assert cmd
assert cmd
assert cmd
assert cmd
client
originalLog log
client
log originalLog
cmd client capturedCommands
assert cmd
assert cmd
assert cmd
assert cmd
result
assert result
result
assert result
result
assert result
assert result
result
assert result
assert result
result
assert result
assert result
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
succeeded
assert succeeded
failed
assert failed
inProgress
assert inProgress
client
client
assert client capturedCommands length
cmd client capturedCommands
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
client
client
client
client
assert client capturedCommands length
showCmd client capturedCommands
assert showCmd
assert showCmd
assert showCmd
assert showCmd
timelineCmd client capturedCommands
assert timelineCmd
assert timelineCmd
artifactsCmd client capturedCommands
assert artifactsCmd
assert artifactsCmd
client
client
assert client capturedCommands length
cmd client capturedCommands
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
client
client branch reason top
assert client capturedCommands length
cmd client capturedCommands
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
scriptName
args process argv
args length args args
process
args
command args
commandArgs args
command
commandArgs
commandArgs
commandArgs
colors
process
DEFAULT_WATCH_INTERVAL
=
30
;
const
NUMERIC_ID_PATTERN
=
/ ^ \d + $ /
;
const
MAX_ID_LENGTH
=
15
;
const
BRANCH_PATTERN
=
/ ^ [ a- z A- Z 0- 9 _\- ./] + $ /
;
const
MAX_BRANCH_LENGTH
=
256
;
const
PARAMETER_PATTERN
=
/ ^ [ a- z A- Z _] [ a- z A- Z 0- 9 _] * =[ a- z A- Z 0- 9 _\- ./: +] * $ /
;
const
MAX_PARAMETER_LENGTH
=
256
;
const
ARTIFACT_NAME_PATTERN
=
/ ^ [ a- z A- Z 0- 9 _\- .] + $ /
;
const
MAX_ARTIFACT_NAME_LENGTH
=
256
;
const
MIN_WATCH_INTERVAL
=
5
;
const
MAX_WATCH_INTERVAL
=
3600
;
interface
Build
{
:
number
;
:
string
;
:
string
;
?
:
string
;
?
:
string
;
?
:
string
;
?
:
string
;
?
:
string
;
?
:
{
?
:
string
}
;
?
:
{
?
:
string
}
;
}
interface
TimelineRecord
{
:
string
;
?
:
string
;
:
string
;
?
:
string
;
?
:
string
;
?
:
string
;
?
:
number
;
?
:
{
?
:
number
}
;
}
interface
Timeline
{
:
[
]
;
}
interface
Artifact
{
:
string
;
?
:
{
?
:
string
;
?
:
{
?
:
string
}
;
}
;
}
interface
QueueArgs
{
:
string
;
:
string
;
:
string
[
]
;
:
boolean
;
:
boolean
;
}
interface
StatusArgs
{
:
string
;
:
string
;
:
string
;
:
string
;
:
boolean
;
:
number
;
:
string
;
:
string
;
:
boolean
;
:
boolean
;
}
interface
CancelArgs
{
:
string
;
:
string
;
:
boolean
;
:
boolean
;
}
const
=
{
red
:
(
:
string
)
=>
` \x1b[0;31m ${ text} \x1b[0m `
,
green
:
(
:
string
)
=>
` \x1b[0;32m ${ text} \x1b[0m `
,
yellow
:
(
:
string
)
=>
` \x1b[0;33m ${ text} \x1b[0m `
,
blue
:
(
:
string
)
=>
` \x1b[0;34m ${ text} \x1b[0m `
,
cyan
:
(
:
string
)
=>
` \x1b[0;36m ${ text} \x1b[0m `
,
gray
:
(
:
string
)
=>
` \x1b[0;90m ${ text} \x1b[0m `
,
}
;
function
validateNumericId
(
:
string
,
:
string
)
:
void
{
if
(
!
)
{
return
;
}
if
(
.
>
MAX_ID_LENGTH
)
{
console
.
error
(
.
red
(
` Error: ${ name} is too long (max ${ MAX_ID_LENGTH } characters) `
)
)
;
.
exit
(
1
)
;
}
if
(
!
NUMERIC_ID_PATTERN
.
test
(
)
)
{
console
.
error
(
.
red
(
` Error: ${ name} must contain only digits `
)
)
;
.
exit
(
1
)
;
}
}
function
validateBranch
(
:
string
)
:
void
{
if
(
!
)
{
return
;
}
if
(
.
>
MAX_BRANCH_LENGTH
)
{
console
.
error
(
.
red
(
` Error: --branch is too long (max ${ MAX_BRANCH_LENGTH } characters) `
)
)
;
.
exit
(
1
)
;
}
if
(
!
BRANCH_PATTERN
.
test
(
)
)
{
console
.
error
(
.
red
(
'Error: --branch contains invalid characters'
)
)
;
console
.
log
(
'Allowed: alphanumeric, hyphens, underscores, slashes, dots'
)
;
.
exit
(
1
)
;
}
}
function
validateParameters
(
:
string
[
]
)
:
void
{
if
(
!
.
)
{
return
;
}
for
(
const
of
)
{
if
(
.
>
MAX_PARAMETER_LENGTH
)
{
console
.
error
(
.
red
(
` Error: Parameter ' ${ parameter. substring ( 0 , 20 ) } ...' is too long (max ${ MAX_PARAMETER_LENGTH } characters) `
)
)
;
.
exit
(
1
)
;
}
if
(
!
PARAMETER_PATTERN
.
test
(
)
)
{
console
.
error
(
.
red
(
` Error: Invalid parameter format ' ${ parameter} ' `
)
)
;
console
.
log
(
'Expected format: KEY=value (alphanumeric, underscores, hyphens, dots, slashes, colons, plus signs, spaces in value)'
)
;
.
exit
(
1
)
;
}
}
}
function
validateArtifactName
(
:
string
)
:
void
{
if
(
!
)
{
return
;
}
if
(
.
>
MAX_ARTIFACT_NAME_LENGTH
)
{
console
.
error
(
.
red
(
` Error: --download-artifact name is too long (max ${ MAX_ARTIFACT_NAME_LENGTH } characters) `
)
)
;
.
exit
(
1
)
;
}
if
(
!
ARTIFACT_NAME_PATTERN
.
test
(
)
)
{
console
.
error
(
.
red
(
'Error: --download-artifact name contains invalid characters'
)
)
;
console
.
log
(
'Allowed: alphanumeric, hyphens, underscores, dots'
)
;
.
exit
(
1
)
;
}
if
(
.
includes
(
'..'
)
||
.
startsWith
(
'.'
)
||
.
startsWith
(
'/'
)
||
.
startsWith
(
'\\'
)
)
{
console
.
error
(
.
red
(
'Error: --download-artifact name contains unsafe path components'
)
)
;
.
exit
(
1
)
;
}
}
function
validateWatchInterval
(
:
number
)
:
void
{
if
(
<
MIN_WATCH_INTERVAL
||
>
MAX_WATCH_INTERVAL
)
{
console
.
error
(
.
red
(
` Error: Watch interval must be between ${ MIN_WATCH_INTERVAL } and ${ MAX_WATCH_INTERVAL } seconds `
)
)
;
.
exit
(
1
)
;
}
}
function
commandExists
(
:
string
)
:
boolean
{
try
{
execSync
(
` ${ process. platform === 'win32' ? 'where' : 'which' } ${ command} `
,
{
:
'ignore'
}
)
;
return
true
;
}
catch
{
return
false
;
}
}
function
hasAzureDevOpsExtension
(
)
:
boolean
{
try
{
execSync
(
'az extension show --name azure-devops'
,
{
:
'ignore'
}
)
;
return
true
;
}
catch
{
return
false
;
}
}
function
getCurrentBranch
(
)
:
string
{
try
{
return
execSync
(
'git branch --show-current'
,
{
:
'utf8'
,
:
[
'pipe'
,
'pipe'
,
'ignore'
]
}
)
.
trim
(
)
;
}
catch
{
return
''
;
}
}
function
ensureAzureCli
(
)
:
void
{
if
(
!
commandExists
(
'az'
)
)
{
console
.
error
(
.
red
(
'Error: Azure CLI (az) is not installed.'
)
)
;
console
.
log
(
'Install it with: brew install azure-cli (macOS) or see https://docs.microsoft.com/en-us/cli/azure/install-azure-cli'
)
;
console
.
log
(
'Then add the DevOps extension: az extension add --name azure-devops'
)
;
.
exit
(
1
)
;
}
if
(
!
hasAzureDevOpsExtension
(
)
)
{
console
.
log
(
.
yellow
(
'Installing azure-devops extension...'
)
)
;
try
{
execSync
(
'az extension add --name azure-devops'
,
{
:
'inherit'
}
)
;
}
catch
{
console
.
error
(
.
red
(
'Failed to install azure-devops extension.'
)
)
;
.
exit
(
1
)
;
}
}
}
function
sleep
(
:
number
)
:
Promise
<
void
>
{
return
new
Promise
(
=>
setTimeout
(
,
*
1000
)
)
;
}
function
clearScreen
(
)
:
void
{
.
.
write
(
'\x1Bc'
)
;
}
function
formatStatus
(
:
string
)
:
string
{
switch
(
)
{
case
'completed'
:
return
.
green
(
'completed'
)
;
case
'inProgress'
:
return
.
blue
(
'in progress'
)
;
case
'notStarted'
:
return
.
gray
(
'not started'
)
;
case
'cancelling'
:
case
'postponed'
:
return
.
yellow
(
)
;
default
:
return
||
''
;
}
}
function
formatResult
(
:
string
)
:
string
{
switch
(
)
{
case
'succeeded'
:
return
.
green
(
'✓ succeeded'
)
;
case
'failed'
:
return
.
red
(
'✗ failed'
)
;
case
'canceled'
:
return
.
yellow
(
'⊘ canceled'
)
;
case
'partiallySucceeded'
:
return
.
yellow
(
'◐ partially succeeded'
)
;
default
:
return
||
'pending'
;
}
}
function
formatTimelineStatus
(
:
string
,
:
string
)
:
string
{
if
(
===
'completed'
)
{
if
(
===
'succeeded'
)
{
return
.
green
(
'✓'
)
;
}
if
(
===
'failed'
)
{
return
.
red
(
'✗'
)
;
}
if
(
===
'skipped'
)
{
return
.
gray
(
'○'
)
;
}
return
.
yellow
(
'◐'
)
;
}
if
(
===
'inProgress'
)
{
return
.
blue
(
'●'
)
;
}
return
.
gray
(
'○'
)
;
}
function
formatBytes
(
:
number
)
:
string
{
if
(
===
0
)
{
return
'0 B'
;
}
const
=
1024
;
const
=
[
'B'
,
'KB'
,
'MB'
,
'GB'
]
;
const
=
.
floor
(
.
log
(
)
/
.
log
(
)
)
;
return
parseFloat
(
(
/
.
pow
(
,
)
)
.
toFixed
(
2
)
)
+
' '
+
[
]
;
}
function
formatRelativeTime
(
:
string
)
:
string
{
if
(
!
)
{
return
''
;
}
const
=
new
Date
(
)
;
const
=
new
Date
(
)
;
const
=
.
getTime
(
)
-
.
getTime
(
)
;
const
=
.
floor
(
/
60000
)
;
const
=
.
floor
(
/
3600000
)
;
const
=
.
floor
(
/
86400000
)
;
if
(
<
1
)
{
return
'just now'
;
}
if
(
<
60
)
{
return
` ${ diffMins} m ago `
;
}
if
(
<
24
)
{
return
` ${ diffHours} h ago `
;
}
return
` ${ diffDays} d ago `
;
}
function
formatReason
(
:
string
)
:
string
{
switch
(
)
{
case
'manual'
:
return
'Manual'
;
case
'individualCI'
:
return
'CI'
;
case
'batchedCI'
:
return
'Batched CI'
;
case
'schedule'
:
return
'Scheduled'
;
case
'pullRequest'
:
return
'PR'
;
case
'buildCompletion'
:
return
'Build Completion'
;
case
'resourceTrigger'
:
return
'Resource Trigger'
;
default
:
return
||
'Unknown'
;
}
}
function
padOrTruncate
(
:
string
,
:
number
)
:
string
{
if
(
.
>
)
{
return
.
slice
(
0
,
-
1
)
+
'…'
;
}
return
.
padEnd
(
)
;
}
function
displayBuildSummary
(
:
)
:
void
{
const
=
.
;
const
=
.
;
const
=
.
;
const
=
.
;
const
=
(
.
||
''
)
.
replace
(
'refs/heads/'
,
''
)
;
const
=
.
;
const
=
.
;
const
=
.
?.
;
console
.
log
(
''
)
;
console
.
log
(
.
blue
(
'Azure Pipeline Build Status'
)
)
;
console
.
log
(
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
)
;
console
.
log
(
` Build ID: ${ colors. green ( String ( id) ) } `
)
;
console
.
log
(
` Build Number: ${ colors. green ( buildNumber) } `
)
;
console
.
log
(
` Branch: ${ colors. green ( sourceBranch) } `
)
;
console
.
log
(
` Status: ${ formatStatus ( status) } `
)
;
console
.
log
(
` Result: ${ formatResult ( result || '' ) } `
)
;
if
(
)
{
console
.
log
(
` Requested By: ${ colors. cyan ( requestedBy) } `
)
;
}
if
(
)
{
console
.
log
(
` Started: ${ colors. gray ( startTime) } `
)
;
}
if
(
)
{
console
.
log
(
` Finished: ${ colors. gray ( finishTime) } `
)
;
}
console
.
log
(
` URL: ${ colors. blue ( ` ${ ORGANIZATION } / ${ PROJECT } /_build/results?buildId= ${ id} ` ) } `
)
;
console
.
log
(
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
)
;
}
function
displayBuildList
(
:
[
]
)
:
void
{
console
.
log
(
''
)
;
console
.
log
(
.
blue
(
'Recent Builds'
)
)
;
console
.
log
(
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
)
;
console
.
log
(
.
gray
(
` ${ 'ID' . padEnd ( 10 ) } ${ 'Status' . padEnd ( 14 ) } ${ 'Reason' . padEnd ( 12 ) } ${ 'Branch' . padEnd ( 25 ) } ${ 'Requested By' . padEnd ( 20 ) } ${ 'Started' . padEnd ( 12 ) } `
)
)
;
console
.
log
(
'─────────────────────────────────────────────────────────────────────────────────────────────────────────────────'
)
;
if
(
!
||
.
===
0
)
{
console
.
log
(
.
gray
(
'No builds found'
)
)
;
console
.
log
(
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
)
;
return
;
}
for
(
const
of
)
{
const
=
String
(
.
)
.
padEnd
(
10
)
;
const
=
padOrTruncate
(
(
.
||
''
)
.
replace
(
'refs/heads/'
,
''
)
,
25
)
;
const
=
padOrTruncate
(
.
?.
||
.
?.
||
'Unknown'
,
20
)
;
const
=
padOrTruncate
(
formatReason
(
.
||
''
)
,
12
)
;
const
=
padOrTruncate
(
formatRelativeTime
(
.
||
''
)
,
12
)
;
let
:
string
;
if
(
.
===
'completed'
)
{
switch
(
.
)
{
case
'succeeded'
:
=
.
green
(
'✓ succeeded'
.
padEnd
(
14
)
)
;
break
;
case
'failed'
:
=
.
red
(
'✗ failed'
.
padEnd
(
14
)
)
;
break
;
case
'canceled'
:
=
.
yellow
(
'⊘ canceled'
.
padEnd
(
14
)
)
;
break
;
case
'partiallySucceeded'
:
=
.
yellow
(
'◐ partial'
.
padEnd
(
14
)
)
;
break
;
default
:
=
.
gray
(
(
.
||
'unknown'
)
.
padEnd
(
14
)
)
;
}
}
else
if
(
.
===
'inProgress'
)
{
=
.
blue
(
'● in progress'
.
padEnd
(
14
)
)
;
}
else
if
(
.
===
'notStarted'
)
{
=
.
gray
(
'○ queued'
.
padEnd
(
14
)
)
;
}
else
if
(
.
===
'cancelling'
)
{
=
.
yellow
(
'⊘ cancelling'
.
padEnd
(
14
)
)
;
}
else
{
=
.
gray
(
(
.
||
'unknown'
)
.
padEnd
(
14
)
)
;
}
console
.
log
(
` ${ colors. cyan ( id) } ${ statusStr} ${ reason} ${ branch} ${ requestedBy} ${ colors. gray ( started) } `
)
;
}
console
.
log
(
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
)
;
console
.
log
(
''
)
;
console
.
log
(
.
gray
(
'Use --build-id <id> to see details for a specific build'
)
)
;
}
function
displayTimeline
(
:
|
null
)
:
void
{
console
.
log
(
''
)
;
console
.
log
(
.
blue
(
'Pipeline Stages'
)
)
;
console
.
log
(
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
)
;
if
(
!
||
!
.
)
{
console
.
log
(
.
gray
(
'Timeline not available'
)
)
;
console
.
log
(
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
)
;
return
;
}
const
=
.
;
const
=
.
filter
(
=>
.
===
'Stage'
)
;
const
=
.
filter
(
=>
.
===
'Phase'
)
;
const
=
.
filter
(
=>
.
===
'Job'
)
;
const
=
new
Map< string , string >
(
)
;
for
(
const
of
)
{
if
(
.
)
{
.
set
(
.
,
.
)
;
}
}
.
sort
(
(
,
)
=>
(
.
||
0
)
-
(
.
||
0
)
)
;
for
(
const
of
)
{
const
=
formatTimelineStatus
(
.
||
''
,
.
||
''
)
;
const
=
.
||
'Unknown'
;
console
.
log
(
` ${ status} ${ name} `
)
;
const
=
new
Set
(
.
filter
(
=>
.
===
.
)
.
map
(
=>
.
)
)
;
const
=
.
filter
(
=>
.
&&
.
has
(
.
)
)
;
.
sort
(
(
,
)
=>
(
.
||
0
)
-
(
.
||
0
)
)
;
for
(
const
of
)
{
const
=
formatTimelineStatus
(
.
||
''
,
.
||
''
)
;
const
=
.
||
'Unknown'
;
const
=
.
?.
;
const
=
?
.
gray
(
` (log # ${ logId} ) `
)
:
''
;
console
.
log
(
` ${ jobStatus} ${ jobName} ${ logInfo} `
)
;
}
}
console
.
log
(
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
)
;
}
function
displayArtifacts
(
:
[
]
)
:
void
{
console
.
log
(
''
)
;
console
.
log
(
.
blue
(
'Build Artifacts'
)
)
;
console
.
log
(
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
)
;
if
(
!
||
.
===
0
)
{
console
.
log
(
.
gray
(
'No artifacts available'
)
)
;
console
.
log
(
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
)
;
return
;
}
for
(
const
of
)
{
const
=
.
||
'Unknown'
;
const
=
.
?.
?.
;
if
(
!
||
parseInt
(
,
10
)
===
0
)
{
continue
;
}
const
=
` ( ${ formatBytes ( parseInt ( size, 10 ) ) } ) `
;
console
.
log
(
` ${ colors. cyan ( name) } ${ colors. gray ( sizeStr) } `
)
;
}
console
.
log
(
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
)
;
}
function
displayNextSteps
(
:
string
)
:
void
{
console
.
log
(
''
)
;
console
.
log
(
.
blue
(
'Next Steps'
)
)
;
console
.
log
(
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
)
;
console
.
log
(
.
gray
(
` Download artifact: status --build-id ${ buildId} --download-artifact <name> `
)
)
;
console
.
log
(
.
gray
(
` Download log: status --build-id ${ buildId} --download-log <id> `
)
)
;
console
.
log
(
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
)
;
}
class
AzureDevOpsClient
{
protected
readonly
:
string
;
protected
readonly
:
string
;
constructor
(
:
string
,
:
string
)
{
this
.
=
;
this
.
=
;
}
protected
runAzCommand
(
:
string
[
]
)
:
Promise
<
string
>
{
return
new
Promise
(
(
,
)
=>
{
const
=
.
===
'win32'
?
'az.cmd'
:
'az'
;
const
=
spawn
(
,
,
{
:
false
}
)
;
let
=
''
;
let
=
''
;
.
.
on
(
'data'
,
(
:
)
=>
{
+=
.
toString
(
)
;
}
)
;
.
.
on
(
'data'
,
(
:
)
=>
{
+=
.
toString
(
)
;
}
)
;
.
on
(
'close'
,
(
:
number
|
null
)
=>
{
if
(
===
0
)
{
resolve
(
)
;
}
else
{
reject
(
new
Error
(
||
||
` Command failed with code ${ code} `
)
)
;
}
}
)
;
.
on
(
'error'
,
)
;
}
)
;
}
private
async
rest < T >
(
:
string
,
:
string
,
?
:
string
)
:
Promise
<
T
>
{
const
=
[
'rest'
,
'--method'
,
,
'--url'
,
,
'--resource'
,
'499b84ac-1321-427f-aa17-267ca6975798'
,
]
;
if
(
)
{
const
=
.
tmpdir
(
)
;
const
=
.
join
(
,
` azdo-request- ${ Date. now ( ) } .json `
)
;
.
writeFileSync
(
,
)
;
.
push
(
'--headers'
,
'Content-Type=application/json'
)
;
.
push
(
'--body'
,
` @ ${ bodyFile} `
)
;
try
{
const
=
await
this
.
runAzCommand
(
)
;
return
JSON
.
parse
(
)
;
}
finally
{
try
{
.
unlinkSync
(
)
;
}
catch
{
}
}
}
const
=
await
this
.
runAzCommand
(
)
;
return
JSON
.
parse
(
)
;
}
async
queueBuild
(
:
string
,
:
string
,
:
string
[
]
=
[
]
)
:
Promise
<
>
{
const
=
[
'pipelines'
,
'run'
,
'--organization'
,
this
.
,
'--project'
,
this
.
,
'--id'
,
,
'--branch'
,
,
]
;
if
(
.
>
0
)
{
.
push
(
'--parameters'
,
...
)
;
}
.
push
(
'--output'
,
'json'
)
;
const
=
await
this
.
runAzCommand
(
)
;
return
JSON
.
parse
(
)
;
}
async
getBuild
(
:
string
)
:
Promise
<
|
null
>
{
try
{
const
=
[
'pipelines'
,
'build'
,
'show'
,
'--organization'
,
this
.
,
'--project'
,
this
.
,
'--id'
,
,
'--output'
,
'json'
,
]
;
const
=
await
this
.
runAzCommand
(
)
;
return
JSON
.
parse
(
)
;
}
catch
{
return
null
;
}
}
async
listBuilds
(
:
string
,
:
{
?
:
string
;
?
:
string
;
?
:
number
}
=
{
}
)
:
Promise
<
[
]
>
{
try
{
const
=
[
'pipelines'
,
'build'
,
'list'
,
'--organization'
,
this
.
,
'--project'
,
this
.
,
'--definition-ids'
,
,
'--top'
,
String
(
.
||
20
)
,
'--output'
,
'json'
,
]
;
if
(
.
)
{
.
push
(
'--branch'
,
.
)
;
}
if
(
.
)
{
.
push
(
'--reason'
,
.
)
;
}
const
=
await
this
.
runAzCommand
(
)
;
return
JSON
.
parse
(
)
;
}
catch
{
return
[
]
;
}
}
async
findRecentBuild
(
:
string
,
:
string
)
:
Promise
<
string
>
{
try
{
const
=
[
'pipelines'
,
'build'
,
'list'
,
'--organization'
,
this
.
,
'--project'
,
this
.
,
'--definition-ids'
,
,
'--branch'
,
,
'--top'
,
'1'
,
'--query'
,
'[0].id'
,
'--output'
,
'tsv'
,
]
;
const
=
await
this
.
runAzCommand
(
)
;
return
.
trim
(
)
;
}
catch
{
return
''
;
}
}
async
cancelBuild
(
:
string
)
:
Promise
<
>
{
const
=
` ${ this . organization} / ${ this . project} /_apis/build/builds/ ${ buildId} ?api-version=7.0 `
;
return
this
.
rest < Build>
(
'patch'
,
,
JSON
.
stringify
(
{
:
'cancelling'
}
)
)
;
}
async
getTimeline
(
:
string
)
:
Promise
<
|
null
>
{
try
{
const
=
` ${ this . organization} / ${ this . project} /_apis/build/builds/ ${ buildId} /timeline?api-version=7.0 `
;
return
await
this
.
rest < Timeline>
(
'get'
,
)
;
}
catch
{
return
null
;
}
}
async
getArtifacts
(
:
string
)
:
Promise
<
[
]
>
{
try
{
const
=
` ${ this . organization} / ${ this . project} /_apis/build/builds/ ${ buildId} /artifacts?api-version=7.0 `
;
const
=
await
this
.
rest < { value: Artifact[ ] } >
(
'get'
,
)
;
return
.
||
[
]
;
}
catch
{
return
[
]
;
}
}
async
downloadLog
(
:
string
,
:
string
)
:
Promise
<
string
>
{
const
=
` ${ this . organization} / ${ this . project} /_apis/build/builds/ ${ buildId} /logs/ ${ logId} ?api-version=7.0 `
;
const
=
[
'rest'
,
'--method'
,
'get'
,
'--url'
,
,
'--resource'
,
'499b84ac-1321-427f-aa17-267ca6975798'
]
;
const
=
await
this
.
runAzCommand
(
)
;
const
=
.
tmpdir
(
)
;
const
=
.
join
(
,
` build- ${ buildId} -log- ${ logId} .txt `
)
;
console
.
log
(
.
blue
(
` Downloading log # ${ logId} ... `
)
)
;
console
.
log
(
.
gray
(
` Destination: ${ outputPath} `
)
)
;
.
writeFileSync
(
,
)
;
return
;
}
async
downloadArtifact
(
:
string
,
:
string
)
:
Promise
<
string
>
{
const
=
await
this
.
getArtifacts
(
)
;
const
=
.
find
(
=>
.
===
)
;
if
(
!
)
{
const
=
.
map
(
=>
.
)
.
join
(
', '
)
;
throw
new
Error
(
` Artifact ' ${ artifactName} ' not found. Available artifacts: ${ available || 'none' } `
)
;
}
const
=
.
?.
;
if
(
!
)
{
throw
new
Error
(
` Artifact ' ${ artifactName} ' has no download URL `
)
;
}
const
=
.
tmpdir
(
)
;
const
=
.
join
(
,
` ${ artifactName} .zip `
)
;
console
.
log
(
.
blue
(
` Downloading artifact ' ${ artifactName} '... `
)
)
;
console
.
log
(
.
gray
(
` Destination: ${ outputPath} `
)
)
;
const
=
[
'account'
,
'get-access-token'
,
'--resource'
,
'499b84ac-1321-427f-aa17-267ca6975798'
,
'--query'
,
'accessToken'
,
'--output'
,
'tsv'
]
;
const
=
(
await
this
.
runAzCommand
(
)
)
.
trim
(
)
;
const
=
await
fetch
(
,
{
:
{
'Authorization'
:
` Bearer ${ token} `
}
,
:
'follow'
,
}
)
;
if
(
!
.
)
{
throw
new
Error
(
` Failed to download artifact: ${ response. status} ${ response. statusText} `
)
;
}
const
=
.
from
(
await
.
arrayBuffer
(
)
)
;
.
writeFileSync
(
,
)
;
return
;
}
}
function
printQueueUsage
(
)
:
void
{
const
=
'node .github/skills/azure-pipelines/azure-pipeline.ts queue'
;
console
.
log
(
` Usage: ${ scriptName} [options] `
)
;
console
.
log
(
''
)
;
console
.
log
(
'Queue an Azure DevOps pipeline build for VS Code.'
)
;
console
.
log
(
''
)
;
console
.
log
(
'Options:'
)
;
console
.
log
(
' --branch <name> Source branch to build (default: current git branch)'
)
;
console
.
log
(
' --definition <id> Pipeline definition ID (default: 111)'
)
;
console
.
log
(
' --parameter <entry> Pipeline parameter in "KEY=value" format (repeatable); use this for values with spaces'
)
;
console
.
log
(
' --parameters <list> Space-separated parameter list in "KEY=value KEY2=value2" format (values must not contain spaces)'
)
;
console
.
log
(
' --dry-run Print the command without executing'
)
;
console
.
log
(
' --help Show this help message'
)
;
console
.
log
(
''
)
;
console
.
log
(
'Examples:'
)
;
console
.
log
(
` ${ scriptName} # Queue build on current branch `
)
;
console
.
log
(
` ${ scriptName} --branch my-feature # Queue build on specific branch `
)
;
console
.
log
(
` ${ scriptName} --parameter "VSCODE_BUILD_WEB=false" --parameter "VSCODE_PUBLISH=false" `
)
;
console
.
log
(
` ${ scriptName} --parameter "VSCODE_BUILD_TYPE=Product Build" # Parameter values with spaces `
)
;
}
function
parseQueueArgs
(
:
string
[
]
)
:
{
const
:
=
{
:
''
,
:
DEFAULT_DEFINITION_ID
,
:
[
]
,
:
false
,
:
false
,
}
;
for
(
let
=
0
;
<
.
;
++
)
{
const
=
[
]
;
switch
(
)
{
case
'--branch'
:
.
=
[
++
]
||
''
;
break
;
case
'--definition'
:
.
=
[
++
]
||
DEFAULT_DEFINITION_ID
;
break
;
case
'--parameter'
:
{
const
=
[
++
]
||
''
;
if
(
)
{
.
.
push
(
)
;
}
break
;
}
case
'--parameters'
:
.
.
push
(
...
(
[
++
]
||
''
)
.
split
(
' '
)
.
filter
(
=>
.
>
0
)
)
;
break
;
case
'--dry-run'
:
.
=
true
;
break
;
case
'--help'
:
.
=
true
;
break
;
default
:
console
.
error
(
.
red
(
` Error: Unknown option: ${ arg} `
)
)
;
printQueueUsage
(
)
;
.
exit
(
1
)
;
}
}
return
;
}
function
validateQueueArgs
(
:
)
:
void
{
validateNumericId
(
.
,
'--definition'
)
;
validateBranch
(
.
)
;
validateParameters
(
.
)
;
}
async
function
runQueueCommand
(
:
string
[
]
)
:
Promise
<
void
>
{
const
=
parseQueueArgs
(
)
;
if
(
.
)
{
printQueueUsage
(
)
;
.
exit
(
0
)
;
}
validateQueueArgs
(
)
;
ensureAzureCli
(
)
;
let
=
.
;
if
(
!
)
{
=
getCurrentBranch
(
)
;
if
(
!
)
{
console
.
error
(
.
red
(
'Error: Could not determine current git branch.'
)
)
;
console
.
log
(
'Please specify a branch with --branch <name>'
)
;
.
exit
(
1
)
;
}
validateBranch
(
)
;
}
console
.
log
(
.
blue
(
'Queueing Azure Pipeline Build'
)
)
;
console
.
log
(
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
)
;
console
.
log
(
` Organization: ${ colors. green ( ORGANIZATION ) } `
)
;
console
.
log
(
` Project: ${ colors. green ( PROJECT ) } `
)
;
console
.
log
(
` Definition: ${ colors. green ( parsedArgs. definitionId) } `
)
;
console
.
log
(
` Branch: ${ colors. green ( branch) } `
)
;
if
(
.
.
>
0
)
{
console
.
log
(
` Parameters: ${ colors. green ( parsedArgs. parameters. join ( ' ' ) ) } `
)
;
}
console
.
log
(
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
)
;
console
.
log
(
''
)
;
if
(
.
)
{
console
.
log
(
.
yellow
(
'Dry run - command would be:'
)
)
;
const
=
[
'pipelines'
,
'run'
,
'--organization'
,
ORGANIZATION
,
'--project'
,
PROJECT
,
'--id'
,
.
,
'--branch'
,
,
]
;
if
(
.
.
>
0
)
{
.
push
(
'--parameters'
,
...
.
)
;
}
.
push
(
'--output'
,
'json'
)
;
const
=
.
map
(
=>
.
includes
(
' '
)
?
` " ${ a} " `
:
)
;
console
.
log
(
` az ${ displayArgs. join ( ' ' ) } `
)
;
.
exit
(
0
)
;
}
console
.
log
(
.
blue
(
'Queuing build...'
)
)
;
try
{
const
=
new
AzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
const
=
await
.
queueBuild
(
.
,
,
.
)
;
const
=
.
;
const
=
.
;
const
=
` ${ ORGANIZATION } / ${ PROJECT } /_build/results?buildId= ${ buildId} `
;
console
.
log
(
''
)
;
console
.
log
(
.
green
(
'✓ Build queued successfully!'
)
)
;
console
.
log
(
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
)
;
console
.
log
(
` Build ID: ${ colors. green ( String ( buildId) ) } `
)
;
if
(
)
{
console
.
log
(
` Build Number: ${ colors. green ( buildNumber) } `
)
;
}
console
.
log
(
` URL: ${ colors. blue ( buildUrl) } `
)
;
console
.
log
(
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
)
;
console
.
log
(
''
)
;
console
.
log
(
'To check status, run:'
)
;
console
.
log
(
` node .github/skills/azure-pipelines/azure-pipeline.ts status --build-id ${ buildId} `
)
;
console
.
log
(
''
)
;
console
.
log
(
'To watch progress:'
)
;
console
.
log
(
` node .github/skills/azure-pipelines/azure-pipeline.ts status --build-id ${ buildId} --watch `
)
;
}
catch
(
)
{
const
=
instanceof
Error
?
:
new
Error
(
String
(
)
)
;
console
.
error
(
.
red
(
'Error queuing build:'
)
)
;
console
.
error
(
.
)
;
.
exit
(
1
)
;
}
}
function
printStatusUsage
(
)
:
void
{
const
=
'node .github/skills/azure-pipelines/azure-pipeline.ts status'
;
console
.
log
(
` Usage: ${ scriptName} [options] `
)
;
console
.
log
(
''
)
;
console
.
log
(
'Get status and logs of an Azure DevOps pipeline build.'
)
;
console
.
log
(
''
)
;
console
.
log
(
'Options:'
)
;
console
.
log
(
' --build-id <id> Specific build ID (default: list last 20 builds)'
)
;
console
.
log
(
' --branch <name> Filter builds by branch name (shows last 20 builds for branch)'
)
;
console
.
log
(
' --reason <reason> Filter builds by reason (manual, individualCI, batchedCI, schedule, pullRequest)'
)
;
console
.
log
(
' --definition <id> Pipeline definition ID (default: 111)'
)
;
console
.
log
(
' --watch [seconds] Continuously poll status until build completes (default: 30)'
)
;
console
.
log
(
' --download-log <id> Download a specific log to /tmp'
)
;
console
.
log
(
' --download-artifact <name> Download artifact to /tmp'
)
;
console
.
log
(
' --json Output raw JSON'
)
;
console
.
log
(
' --help Show this help message'
)
;
console
.
log
(
''
)
;
console
.
log
(
'Examples:'
)
;
console
.
log
(
` ${ scriptName} # List last 20 builds `
)
;
console
.
log
(
` ${ scriptName} --branch main # List last 20 builds for main branch `
)
;
console
.
log
(
` ${ scriptName} --reason schedule # List last 20 scheduled builds `
)
;
console
.
log
(
` ${ scriptName} --build-id 123456 # Status of specific build `
)
;
console
.
log
(
` ${ scriptName} --watch # Watch build until completion (30s interval) `
)
;
console
.
log
(
` ${ scriptName} --watch 60 # Watch with 60s interval `
)
;
console
.
log
(
` ${ scriptName} --build-id 123456 --download-log 5 # Download log to /tmp `
)
;
}
function
parseStatusArgs
(
:
string
[
]
)
:
{
const
:
=
{
:
''
,
:
''
,
:
''
,
:
DEFAULT_DEFINITION_ID
,
:
false
,
:
DEFAULT_WATCH_INTERVAL
,
:
''
,
:
''
,
:
false
,
:
false
,
}
;
for
(
let
=
0
;
<
.
;
++
)
{
const
=
[
]
;
switch
(
)
{
case
'--build-id'
:
.
=
[
++
]
||
''
;
break
;
case
'--branch'
:
.
=
[
++
]
||
''
;
break
;
case
'--reason'
:
.
=
[
++
]
||
''
;
break
;
case
'--definition'
:
.
=
[
++
]
||
DEFAULT_DEFINITION_ID
;
break
;
case
'--watch'
:
.
=
true
;
if
(
[
+
1
]
&&
/ ^ \d + $ /
.
test
(
[
+
1
]
)
)
{
.
=
parseInt
(
[
++
]
,
10
)
||
DEFAULT_WATCH_INTERVAL
;
}
break
;
case
'--download-log'
:
.
=
[
++
]
||
''
;
break
;
case
'--download-artifact'
:
.
=
[
++
]
||
''
;
break
;
case
'--json'
:
.
=
true
;
break
;
case
'--help'
:
.
=
true
;
break
;
default
:
console
.
error
(
.
red
(
` Error: Unknown option: ${ arg} `
)
)
;
printStatusUsage
(
)
;
.
exit
(
1
)
;
}
}
return
;
}
function
validateStatusArgs
(
:
)
:
void
{
validateNumericId
(
.
,
'--build-id'
)
;
validateNumericId
(
.
,
'--definition'
)
;
validateNumericId
(
.
,
'--download-log'
)
;
validateArtifactName
(
.
)
;
if
(
.
)
{
validateWatchInterval
(
.
)
;
}
}
async
function
runStatusCommand
(
:
string
[
]
)
:
Promise
<
void
>
{
const
=
parseStatusArgs
(
)
;
if
(
.
)
{
printStatusUsage
(
)
;
.
exit
(
0
)
;
}
validateStatusArgs
(
)
;
ensureAzureCli
(
)
;
const
=
new
AzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
let
=
.
;
if
(
!
&&
!
.
&&
!
.
&&
!
.
)
{
const
=
await
.
listBuilds
(
.
,
{
:
.
,
:
.
,
:
20
,
}
)
;
if
(
.
)
{
console
.
log
(
JSON
.
stringify
(
,
null
,
2
)
)
;
}
else
{
const
:
string
[
]
=
[
]
;
if
(
.
)
{
.
push
(
` branch: ${ parsedArgs. branch} `
)
;
}
if
(
.
)
{
.
push
(
` reason: ${ parsedArgs. reason} `
)
;
}
if
(
.
>
0
)
{
console
.
log
(
.
gray
(
` Filtering by ${ filters. join ( ', ' ) } `
)
)
;
}
displayBuildList
(
)
;
}
return
;
}
if
(
!
)
{
const
=
getCurrentBranch
(
)
;
if
(
!
)
{
console
.
error
(
.
red
(
'Error: Could not determine current git branch.'
)
)
;
console
.
log
(
'Please specify a build ID with --build-id <id>'
)
;
.
exit
(
1
)
;
}
console
.
log
(
.
gray
(
` Finding most recent build for branch: ${ branch} `
)
)
;
=
await
.
findRecentBuild
(
,
.
)
;
if
(
!
)
{
console
.
error
(
.
red
(
` Error: No builds found for branch ' ${ branch} '. `
)
)
;
console
.
log
(
'You can queue a new build with: node .github/skills/azure-pipelines/azure-pipeline.ts queue'
)
;
.
exit
(
1
)
;
}
}
if
(
.
)
{
try
{
const
=
await
.
downloadLog
(
,
.
)
;
console
.
log
(
.
green
(
` ✓ Log downloaded to: ${ outputPath} `
)
)
;
}
catch
(
)
{
console
.
error
(
.
red
(
(
as
)
.
)
)
;
.
exit
(
1
)
;
}
return
;
}
if
(
.
)
{
try
{
const
=
await
.
downloadArtifact
(
,
.
)
;
console
.
log
(
.
green
(
` ✓ Artifact downloaded to: ${ outputPath} `
)
)
;
}
catch
(
)
{
console
.
error
(
.
red
(
(
as
)
.
)
)
;
.
exit
(
1
)
;
}
return
;
}
if
(
.
)
{
console
.
log
(
.
blue
(
` Watching build ${ buildId} (Ctrl+C to stop) `
)
)
;
console
.
log
(
''
)
;
while
(
true
)
{
const
=
await
.
getBuild
(
)
;
if
(
!
)
{
console
.
error
(
.
red
(
'Error: Could not fetch build status'
)
)
;
.
exit
(
1
)
;
}
clearScreen
(
)
;
if
(
.
)
{
console
.
log
(
JSON
.
stringify
(
,
null
,
2
)
)
;
}
else
{
displayBuildSummary
(
)
;
const
=
await
.
getTimeline
(
)
;
displayTimeline
(
)
;
const
=
await
.
getArtifacts
(
)
;
displayArtifacts
(
)
;
displayNextSteps
(
)
;
}
if
(
.
===
'completed'
)
{
console
.
log
(
''
)
;
console
.
log
(
.
green
(
'Build completed!'
)
)
;
.
exit
(
0
)
;
}
console
.
log
(
''
)
;
console
.
log
(
.
gray
(
` Refreshing in ${ parsedArgs. watchInterval} seconds... (Ctrl+C to stop) `
)
)
;
await
sleep
(
.
)
;
}
}
else
{
const
=
await
.
getBuild
(
)
;
if
(
!
)
{
console
.
error
(
.
red
(
` Error: Could not fetch build status for ID ${ buildId} `
)
)
;
.
exit
(
1
)
;
}
if
(
.
)
{
console
.
log
(
JSON
.
stringify
(
,
null
,
2
)
)
;
}
else
{
displayBuildSummary
(
)
;
const
=
await
.
getTimeline
(
)
;
displayTimeline
(
)
;
const
=
await
.
getArtifacts
(
)
;
displayArtifacts
(
)
;
displayNextSteps
(
)
;
}
}
}
function
printCancelUsage
(
)
:
void
{
const
=
'node .github/skills/azure-pipelines/azure-pipeline.ts cancel'
;
console
.
log
(
` Usage: ${ scriptName} --build-id <id> [options] `
)
;
console
.
log
(
''
)
;
console
.
log
(
'Cancel a running Azure DevOps pipeline build.'
)
;
console
.
log
(
''
)
;
console
.
log
(
'Options:'
)
;
console
.
log
(
' --build-id <id> Build ID to cancel (required)'
)
;
console
.
log
(
' --definition <id> Pipeline definition ID (default: 111)'
)
;
console
.
log
(
' --dry-run Print what would be cancelled without executing'
)
;
console
.
log
(
' --help Show this help message'
)
;
console
.
log
(
''
)
;
console
.
log
(
'Examples:'
)
;
console
.
log
(
` ${ scriptName} --build-id 123456 # Cancel specific build `
)
;
console
.
log
(
` ${ scriptName} --build-id 123456 --dry-run # Show what would be cancelled `
)
;
}
function
parseCancelArgs
(
:
string
[
]
)
:
{
const
:
=
{
:
''
,
:
DEFAULT_DEFINITION_ID
,
:
false
,
:
false
,
}
;
for
(
let
=
0
;
<
.
;
++
)
{
const
=
[
]
;
switch
(
)
{
case
'--build-id'
:
.
=
[
++
]
||
''
;
break
;
case
'--definition'
:
.
=
[
++
]
||
DEFAULT_DEFINITION_ID
;
break
;
case
'--dry-run'
:
.
=
true
;
break
;
case
'--help'
:
.
=
true
;
break
;
default
:
console
.
error
(
.
red
(
` Error: Unknown option: ${ arg} `
)
)
;
printCancelUsage
(
)
;
.
exit
(
1
)
;
}
}
return
;
}
function
validateCancelArgs
(
:
)
:
void
{
validateNumericId
(
.
,
'--build-id'
)
;
validateNumericId
(
.
,
'--definition'
)
;
}
async
function
runCancelCommand
(
:
string
[
]
)
:
Promise
<
void
>
{
const
=
parseCancelArgs
(
)
;
if
(
.
)
{
printCancelUsage
(
)
;
.
exit
(
0
)
;
}
validateCancelArgs
(
)
;
ensureAzureCli
(
)
;
const
=
.
;
if
(
!
)
{
console
.
error
(
.
red
(
'Error: --build-id is required.'
)
)
;
console
.
log
(
''
)
;
console
.
log
(
'To find build IDs, run:'
)
;
console
.
log
(
' node .github/skills/azure-pipelines/azure-pipeline.ts status'
)
;
.
exit
(
1
)
;
}
const
=
new
AzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
const
=
await
.
getBuild
(
)
;
if
(
!
)
{
console
.
error
(
.
red
(
` Error: Could not fetch build status for ID ${ buildId} `
)
)
;
.
exit
(
1
)
;
}
const
=
` ${ ORGANIZATION } / ${ PROJECT } /_build/results?buildId= ${ buildId} `
;
console
.
log
(
''
)
;
console
.
log
(
.
blue
(
'Azure Pipeline Build Cancel'
)
)
;
console
.
log
(
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
)
;
console
.
log
(
` Build ID: ${ colors. green ( String ( build. id) ) } `
)
;
console
.
log
(
` Build Number: ${ colors. green ( build. buildNumber || 'N/A' ) } `
)
;
console
.
log
(
` Status: ${ colors. yellow ( build. status) } `
)
;
console
.
log
(
` URL: ${ colors. blue ( buildUrl) } `
)
;
console
.
log
(
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
)
;
if
(
.
===
'completed'
)
{
console
.
log
(
''
)
;
console
.
log
(
.
yellow
(
'Build is already completed. Nothing to cancel.'
)
)
;
.
exit
(
0
)
;
}
if
(
.
===
'cancelling'
)
{
console
.
log
(
''
)
;
console
.
log
(
.
yellow
(
'Build is already being cancelled.'
)
)
;
.
exit
(
0
)
;
}
if
(
.
)
{
console
.
log
(
''
)
;
console
.
log
(
.
yellow
(
'Dry run - would cancel build:'
)
)
;
console
.
log
(
` Build ID: ${ buildId} `
)
;
console
.
log
(
` API: PATCH ${ ORGANIZATION } / ${ PROJECT } /_apis/build/builds/ ${ buildId} ?api-version=7.0 `
)
;
console
.
log
(
` Body: {"status": "cancelling"} `
)
;
.
exit
(
0
)
;
}
console
.
log
(
''
)
;
console
.
log
(
.
blue
(
'Cancelling build...'
)
)
;
try
{
await
.
cancelBuild
(
)
;
console
.
log
(
''
)
;
console
.
log
(
.
green
(
'✓ Build cancellation requested successfully!'
)
)
;
console
.
log
(
''
)
;
console
.
log
(
'The build will transition to "cancelling" state and then "canceled".'
)
;
console
.
log
(
'Check status with:'
)
;
console
.
log
(
` node .github/skills/azure-pipelines/azure-pipeline.ts status --build-id ${ buildId} `
)
;
}
catch
(
)
{
const
=
instanceof
Error
?
:
new
Error
(
String
(
)
)
;
console
.
error
(
''
)
;
console
.
error
(
.
red
(
'Error cancelling build:'
)
)
;
console
.
error
(
.
)
;
.
exit
(
1
)
;
}
}
class
TestableAzureDevOpsClient
extends
AzureDevOpsClient
{
public
:
string
[
]
[
]
=
[
]
;
private
:
<
string
,
unknown
>
=
new
Map
(
)
;
constructor
(
:
string
,
:
string
)
{
super
(
,
)
;
}
setMockResponse
(
:
string
,
:
unknown
)
:
void
{
this
.
.
set
(
,
)
;
}
protected
runAzCommand
(
:
string
[
]
)
:
Promise
<
string
>
{
this
.
.
push
(
)
;
const
=
.
join
(
' '
)
;
for
(
const
[
,
]
of
this
.
)
{
if
(
.
includes
(
)
)
{
return
Promise
.
resolve
(
JSON
.
stringify
(
)
)
;
}
}
if
(
.
includes
(
'pipelines'
)
&&
.
includes
(
'run'
)
)
{
return
Promise
.
resolve
(
JSON
.
stringify
(
{
:
12345
,
:
'20260218.1'
}
)
)
;
}
if
(
.
includes
(
'pipelines'
)
&&
.
includes
(
'build'
)
&&
.
includes
(
'show'
)
)
{
return
Promise
.
resolve
(
JSON
.
stringify
(
{
:
12345
,
:
'20260218.1'
,
:
'inProgress'
,
:
'refs/heads/main'
}
)
)
;
}
if
(
.
includes
(
'pipelines'
)
&&
.
includes
(
'build'
)
&&
.
includes
(
'list'
)
)
{
return
Promise
.
resolve
(
JSON
.
stringify
(
[
{
:
12345
,
:
'20260218.1'
,
:
'completed'
,
:
'succeeded'
}
]
)
)
;
}
if
(
.
includes
(
'rest'
)
&&
.
includes
(
'patch'
)
)
{
return
Promise
.
resolve
(
JSON
.
stringify
(
{
:
12345
,
:
'cancelling'
}
)
)
;
}
if
(
.
includes
(
'rest'
)
&&
.
includes
(
'timeline'
)
)
{
return
Promise
.
resolve
(
JSON
.
stringify
(
{
:
[
]
}
)
)
;
}
if
(
.
includes
(
'rest'
)
&&
.
includes
(
'artifacts'
)
)
{
return
Promise
.
resolve
(
JSON
.
stringify
(
{
:
[
]
}
)
)
;
}
return
Promise
.
resolve
(
'{}'
)
;
}
}
async
function
runAllTests
(
)
:
Promise
<
void
>
{
const
{
,
}
=
await
import
(
'node:test'
)
;
const
=
await
import
(
'node:assert'
)
;
describe
(
'Validation Functions'
,
(
)
=>
{
it
(
'validateNumericId accepts valid numeric IDs'
,
(
)
=>
{
validateNumericId
(
'12345'
,
'test'
)
;
validateNumericId
(
'1'
,
'test'
)
;
validateNumericId
(
'999999999999999'
,
'test'
)
;
}
)
;
it
(
'validateNumericId accepts empty string'
,
(
)
=>
{
validateNumericId
(
''
,
'test'
)
;
}
)
;
it
(
'validateBranch accepts valid branch names'
,
(
)
=>
{
validateBranch
(
'main'
)
;
validateBranch
(
'feature/my-feature'
)
;
validateBranch
(
'release/v1.0.0'
)
;
validateBranch
(
'user/john_doe/fix-123'
)
;
validateBranch
(
'refs/heads/main'
)
;
}
)
;
it
(
'validateBranch accepts empty string'
,
(
)
=>
{
validateBranch
(
''
)
;
}
)
;
it
(
'validateParameters accepts valid parameter formats'
,
(
)
=>
{
validateParameters
(
[
'KEY=value'
]
)
;
validateParameters
(
[
'MY_VAR=some-value'
]
)
;
validateParameters
(
[
'A=1'
,
'B=2'
,
'C=3'
]
)
;
validateParameters
(
[
'PATH=/usr/bin:path'
]
)
;
}
)
;
it
(
'validateParameters accepts empty list'
,
(
)
=>
{
validateParameters
(
[
]
)
;
}
)
;
it
(
'validateArtifactName accepts valid artifact names'
,
(
)
=>
{
validateArtifactName
(
'my-artifact'
)
;
validateArtifactName
(
'artifact_1.0.0'
)
;
validateArtifactName
(
'Build-Output'
)
;
}
)
;
it
(
'validateArtifactName accepts empty string'
,
(
)
=>
{
validateArtifactName
(
''
)
;
}
)
;
it
(
'validateWatchInterval accepts valid intervals'
,
(
)
=>
{
validateWatchInterval
(
5
)
;
validateWatchInterval
(
30
)
;
validateWatchInterval
(
3600
)
;
}
)
;
}
)
;
describe
(
'Argument Parsing'
,
(
)
=>
{
it
(
'parseQueueArgs parses --branch correctly'
,
(
)
=>
{
const
=
parseQueueArgs
(
[
'--branch'
,
'my-feature'
]
)
;
.
strictEqual
(
.
,
'my-feature'
)
;
}
)
;
it
(
'parseQueueArgs parses --definition correctly'
,
(
)
=>
{
const
=
parseQueueArgs
(
[
'--definition'
,
'222'
]
)
;
.
strictEqual
(
.
,
'222'
)
;
}
)
;
it
(
'parseQueueArgs parses --parameters correctly'
,
(
)
=>
{
const
=
parseQueueArgs
(
[
'--parameters'
,
'KEY=value'
]
)
;
.
deepStrictEqual
(
.
,
[
'KEY=value'
]
)
;
}
)
;
it
(
'parseQueueArgs parses repeated --parameter correctly'
,
(
)
=>
{
const
=
parseQueueArgs
(
[
'--parameter'
,
'A=1'
,
'--parameter'
,
'B=two words'
]
)
;
.
deepStrictEqual
(
.
,
[
'A=1'
,
'B=two words'
]
)
;
}
)
;
it
(
'parseQueueArgs parses --dry-run correctly'
,
(
)
=>
{
const
=
parseQueueArgs
(
[
'--dry-run'
]
)
;
.
strictEqual
(
.
,
true
)
;
}
)
;
it
(
'parseQueueArgs parses combined arguments'
,
(
)
=>
{
const
=
parseQueueArgs
(
[
'--branch'
,
'main'
,
'--definition'
,
'333'
,
'--parameters'
,
'A=1 B=2'
,
'--dry-run'
]
)
;
.
strictEqual
(
.
,
'main'
)
;
.
strictEqual
(
.
,
'333'
)
;
.
deepStrictEqual
(
.
,
[
'A=1'
,
'B=2'
]
)
;
.
strictEqual
(
.
,
true
)
;
}
)
;
it
(
'parseStatusArgs parses --build-id correctly'
,
(
)
=>
{
const
=
parseStatusArgs
(
[
'--build-id'
,
'12345'
]
)
;
.
strictEqual
(
.
,
'12345'
)
;
}
)
;
it
(
'parseStatusArgs parses --branch correctly'
,
(
)
=>
{
const
=
parseStatusArgs
(
[
'--branch'
,
'main'
]
)
;
.
strictEqual
(
.
,
'main'
)
;
}
)
;
it
(
'parseStatusArgs parses --watch without interval'
,
(
)
=>
{
const
=
parseStatusArgs
(
[
'--watch'
]
)
;
.
strictEqual
(
.
,
true
)
;
.
strictEqual
(
.
,
30
)
;
}
)
;
it
(
'parseStatusArgs parses --watch with interval'
,
(
)
=>
{
const
=
parseStatusArgs
(
[
'--watch'
,
'60'
]
)
;
.
strictEqual
(
.
,
true
)
;
.
strictEqual
(
.
,
60
)
;
}
)
;
it
(
'parseStatusArgs parses --download-log correctly'
,
(
)
=>
{
const
=
parseStatusArgs
(
[
'--download-log'
,
'5'
]
)
;
.
strictEqual
(
.
,
'5'
)
;
}
)
;
it
(
'parseStatusArgs parses --download-artifact correctly'
,
(
)
=>
{
const
=
parseStatusArgs
(
[
'--download-artifact'
,
'my-artifact'
]
)
;
.
strictEqual
(
.
,
'my-artifact'
)
;
}
)
;
it
(
'parseStatusArgs parses --json correctly'
,
(
)
=>
{
const
=
parseStatusArgs
(
[
'--json'
]
)
;
.
strictEqual
(
.
,
true
)
;
}
)
;
it
(
'parseCancelArgs parses --build-id correctly'
,
(
)
=>
{
const
=
parseCancelArgs
(
[
'--build-id'
,
'12345'
]
)
;
.
strictEqual
(
.
,
'12345'
)
;
}
)
;
it
(
'parseCancelArgs parses --dry-run correctly'
,
(
)
=>
{
const
=
parseCancelArgs
(
[
'--dry-run'
]
)
;
.
strictEqual
(
.
,
true
)
;
}
)
;
}
)
;
describe
(
'Azure Command Construction'
,
(
)
=>
{
it
(
'queueBuild constructs correct az command'
,
async
(
)
=>
{
const
=
new
TestableAzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
await
.
queueBuild
(
'111'
,
'main'
)
;
.
strictEqual
(
.
.
,
1
)
;
const
=
.
[
0
]
;
.
ok
(
.
includes
(
'pipelines'
)
)
;
.
ok
(
.
includes
(
'run'
)
)
;
.
ok
(
.
includes
(
'--organization'
)
)
;
.
ok
(
.
includes
(
ORGANIZATION
)
)
;
.
ok
(
.
includes
(
'--project'
)
)
;
.
ok
(
.
includes
(
PROJECT
)
)
;
.
ok
(
.
includes
(
'--id'
)
)
;
.
ok
(
.
includes
(
'111'
)
)
;
.
ok
(
.
includes
(
'--branch'
)
)
;
.
ok
(
.
includes
(
'main'
)
)
;
.
ok
(
.
includes
(
'--output'
)
)
;
.
ok
(
.
includes
(
'json'
)
)
;
}
)
;
it
(
'queueBuild includes parameters when provided'
,
async
(
)
=>
{
const
=
new
TestableAzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
await
.
queueBuild
(
'111'
,
'main'
,
[
'KEY=value'
,
'OTHER=test'
]
)
;
const
=
.
[
0
]
;
.
ok
(
.
includes
(
'--parameters'
)
)
;
.
ok
(
.
includes
(
'KEY=value'
)
)
;
.
ok
(
.
includes
(
'OTHER=test'
)
)
;
}
)
;
it
(
'queueBuild passes parameter values with spaces verbatim'
,
async
(
)
=>
{
const
=
new
TestableAzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
await
.
queueBuild
(
'111'
,
'main'
,
[
'VSCODE_BUILD_TYPE=Product Build'
]
)
;
const
=
.
[
0
]
;
.
ok
(
.
includes
(
'--parameters'
)
)
;
.
deepStrictEqual
(
[
.
indexOf
(
'--parameters'
)
+
1
]
,
'VSCODE_BUILD_TYPE=Product Build'
)
;
}
)
;
it
(
'getBuild constructs correct az command'
,
async
(
)
=>
{
const
=
new
TestableAzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
await
.
getBuild
(
'12345'
)
;
.
strictEqual
(
.
.
,
1
)
;
const
=
.
[
0
]
;
.
ok
(
.
includes
(
'pipelines'
)
)
;
.
ok
(
.
includes
(
'build'
)
)
;
.
ok
(
.
includes
(
'show'
)
)
;
.
ok
(
.
includes
(
'--id'
)
)
;
.
ok
(
.
includes
(
'12345'
)
)
;
}
)
;
it
(
'listBuilds constructs correct az command'
,
async
(
)
=>
{
const
=
new
TestableAzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
await
.
listBuilds
(
'111'
)
;
.
strictEqual
(
.
.
,
1
)
;
const
=
.
[
0
]
;
.
ok
(
.
includes
(
'pipelines'
)
)
;
.
ok
(
.
includes
(
'build'
)
)
;
.
ok
(
.
includes
(
'list'
)
)
;
.
ok
(
.
includes
(
'--definition-ids'
)
)
;
.
ok
(
.
includes
(
'111'
)
)
;
.
ok
(
.
includes
(
'--top'
)
)
;
.
ok
(
.
includes
(
'20'
)
)
;
}
)
;
it
(
'listBuilds includes branch filter when provided'
,
async
(
)
=>
{
const
=
new
TestableAzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
await
.
listBuilds
(
'111'
,
{
:
'feature/test'
}
)
;
const
=
.
[
0
]
;
.
ok
(
.
includes
(
'--branch'
)
)
;
.
ok
(
.
includes
(
'feature/test'
)
)
;
}
)
;
it
(
'listBuilds includes reason filter when provided'
,
async
(
)
=>
{
const
=
new
TestableAzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
await
.
listBuilds
(
'111'
,
{
:
'manual'
}
)
;
const
=
.
[
0
]
;
.
ok
(
.
includes
(
'--reason'
)
)
;
.
ok
(
.
includes
(
'manual'
)
)
;
}
)
;
it
(
'listBuilds includes custom top value'
,
async
(
)
=>
{
const
=
new
TestableAzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
await
.
listBuilds
(
'111'
,
{
:
50
}
)
;
const
=
.
[
0
]
;
.
ok
(
.
includes
(
'--top'
)
)
;
.
ok
(
.
includes
(
'50'
)
)
;
}
)
;
it
(
'findRecentBuild constructs correct az command'
,
async
(
)
=>
{
const
=
new
TestableAzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
await
.
findRecentBuild
(
'main'
,
'111'
)
;
const
=
.
[
0
]
;
.
ok
(
.
includes
(
'pipelines'
)
)
;
.
ok
(
.
includes
(
'build'
)
)
;
.
ok
(
.
includes
(
'list'
)
)
;
.
ok
(
.
includes
(
'--branch'
)
)
;
.
ok
(
.
includes
(
'main'
)
)
;
.
ok
(
.
includes
(
'--top'
)
)
;
.
ok
(
.
includes
(
'1'
)
)
;
.
ok
(
.
includes
(
'--query'
)
)
;
.
ok
(
.
includes
(
'[0].id'
)
)
;
.
ok
(
.
includes
(
'--output'
)
)
;
.
ok
(
.
includes
(
'tsv'
)
)
;
}
)
;
it
(
'cancelBuild constructs correct REST API call'
,
async
(
)
=>
{
const
=
new
TestableAzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
await
.
cancelBuild
(
'12345'
)
;
const
=
.
[
0
]
;
.
ok
(
.
includes
(
'rest'
)
)
;
.
ok
(
.
includes
(
'--method'
)
)
;
.
ok
(
.
includes
(
'patch'
)
)
;
.
ok
(
.
join
(
' '
)
.
includes
(
'_apis/build/builds/12345'
)
)
;
}
)
;
it
(
'getTimeline constructs correct REST API call'
,
async
(
)
=>
{
const
=
new
TestableAzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
await
.
getTimeline
(
'12345'
)
;
const
=
.
[
0
]
;
.
ok
(
.
includes
(
'rest'
)
)
;
.
ok
(
.
includes
(
'--method'
)
)
;
.
ok
(
.
includes
(
'get'
)
)
;
.
ok
(
.
join
(
' '
)
.
includes
(
'_apis/build/builds/12345/timeline'
)
)
;
}
)
;
it
(
'getArtifacts constructs correct REST API call'
,
async
(
)
=>
{
const
=
new
TestableAzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
await
.
getArtifacts
(
'12345'
)
;
const
=
.
[
0
]
;
.
ok
(
.
includes
(
'rest'
)
)
;
.
ok
(
.
includes
(
'--method'
)
)
;
.
ok
(
.
includes
(
'get'
)
)
;
.
ok
(
.
join
(
' '
)
.
includes
(
'_apis/build/builds/12345/artifacts'
)
)
;
}
)
;
it
(
'downloadLog constructs correct REST API call'
,
async
(
)
=>
{
const
=
new
TestableAzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
const
=
console
.
;
console
.
log
=
(
)
=>
{
}
;
try
{
await
.
downloadLog
(
'12345'
,
'7'
)
;
}
finally
{
console
.
=
;
}
const
=
.
[
0
]
;
.
ok
(
.
includes
(
'rest'
)
)
;
.
ok
(
.
includes
(
'--method'
)
)
;
.
ok
(
.
includes
(
'get'
)
)
;
.
ok
(
.
join
(
' '
)
.
includes
(
'_apis/build/builds/12345/logs/7'
)
)
;
}
)
;
}
)
;
describe
(
'Display Format Functions'
,
(
)
=>
{
it
(
'formatStatus returns correct format for completed'
,
(
)
=>
{
const
=
formatStatus
(
'completed'
)
;
.
ok
(
.
includes
(
'completed'
)
)
;
}
)
;
it
(
'formatStatus returns correct format for inProgress'
,
(
)
=>
{
const
=
formatStatus
(
'inProgress'
)
;
.
ok
(
.
includes
(
'in progress'
)
)
;
}
)
;
it
(
'formatResult returns correct format for succeeded'
,
(
)
=>
{
const
=
formatResult
(
'succeeded'
)
;
.
ok
(
.
includes
(
'succeeded'
)
)
;
.
ok
(
.
includes
(
'✓'
)
)
;
}
)
;
it
(
'formatResult returns correct format for failed'
,
(
)
=>
{
const
=
formatResult
(
'failed'
)
;
.
ok
(
.
includes
(
'failed'
)
)
;
.
ok
(
.
includes
(
'✗'
)
)
;
}
)
;
it
(
'formatResult returns correct format for canceled'
,
(
)
=>
{
const
=
formatResult
(
'canceled'
)
;
.
ok
(
.
includes
(
'canceled'
)
)
;
.
ok
(
.
includes
(
'⊘'
)
)
;
}
)
;
it
(
'formatBytes formats correctly'
,
(
)
=>
{
.
strictEqual
(
formatBytes
(
0
)
,
'0 B'
)
;
.
strictEqual
(
formatBytes
(
1024
)
,
'1 KB'
)
;
.
strictEqual
(
formatBytes
(
1048576
)
,
'1 MB'
)
;
.
strictEqual
(
formatBytes
(
1073741824
)
,
'1 GB'
)
;
}
)
;
it
(
'formatReason returns correct labels'
,
(
)
=>
{
.
strictEqual
(
formatReason
(
'manual'
)
,
'Manual'
)
;
.
strictEqual
(
formatReason
(
'individualCI'
)
,
'CI'
)
;
.
strictEqual
(
formatReason
(
'pullRequest'
)
,
'PR'
)
;
.
strictEqual
(
formatReason
(
'schedule'
)
,
'Scheduled'
)
;
}
)
;
it
(
'padOrTruncate pads short strings'
,
(
)
=>
{
.
strictEqual
(
padOrTruncate
(
'abc'
,
6
)
,
'abc '
)
;
}
)
;
it
(
'padOrTruncate truncates long strings'
,
(
)
=>
{
.
strictEqual
(
padOrTruncate
(
'abcdefghij'
,
6
)
,
'abcde…'
)
;
}
)
;
it
(
'formatTimelineStatus returns correct symbols'
,
(
)
=>
{
const
=
formatTimelineStatus
(
'completed'
,
'succeeded'
)
;
.
ok
(
.
includes
(
'✓'
)
)
;
const
=
formatTimelineStatus
(
'completed'
,
'failed'
)
;
.
ok
(
.
includes
(
'✗'
)
)
;
const
=
formatTimelineStatus
(
'inProgress'
,
''
)
;
.
ok
(
.
includes
(
'●'
)
)
;
}
)
;
}
)
;
describe
(
'Integration Tests'
,
(
)
=>
{
it
(
'full queue command flow constructs correct az commands'
,
async
(
)
=>
{
const
=
new
TestableAzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
await
.
queueBuild
(
'111'
,
'feature/test'
,
[
'DEBUG=true'
]
)
;
.
strictEqual
(
.
.
,
1
)
;
const
=
.
[
0
]
;
.
ok
(
.
includes
(
'pipelines'
)
)
;
.
ok
(
.
includes
(
'run'
)
)
;
.
ok
(
.
includes
(
'--organization'
)
)
;
.
ok
(
.
includes
(
ORGANIZATION
)
)
;
.
ok
(
.
includes
(
'--project'
)
)
;
.
ok
(
.
includes
(
PROJECT
)
)
;
.
ok
(
.
includes
(
'--id'
)
)
;
.
ok
(
.
includes
(
'111'
)
)
;
.
ok
(
.
includes
(
'--branch'
)
)
;
.
ok
(
.
includes
(
'feature/test'
)
)
;
.
ok
(
.
includes
(
'--parameters'
)
)
;
.
ok
(
.
includes
(
'DEBUG=true'
)
)
;
}
)
;
it
(
'full status command flow constructs correct az commands'
,
async
(
)
=>
{
const
=
new
TestableAzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
await
.
getBuild
(
'99999'
)
;
await
.
getTimeline
(
'99999'
)
;
await
.
getArtifacts
(
'99999'
)
;
.
strictEqual
(
.
.
,
3
)
;
const
=
.
[
0
]
;
.
ok
(
.
includes
(
'build'
)
)
;
.
ok
(
.
includes
(
'show'
)
)
;
.
ok
(
.
includes
(
'--id'
)
)
;
.
ok
(
.
includes
(
'99999'
)
)
;
const
=
.
[
1
]
;
.
ok
(
.
includes
(
'rest'
)
)
;
.
ok
(
.
join
(
' '
)
.
includes
(
'timeline'
)
)
;
const
=
.
[
2
]
;
.
ok
(
.
includes
(
'rest'
)
)
;
.
ok
(
.
join
(
' '
)
.
includes
(
'artifacts'
)
)
;
}
)
;
it
(
'cancel command constructs correct REST API call'
,
async
(
)
=>
{
const
=
new
TestableAzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
await
.
cancelBuild
(
'88888'
)
;
.
strictEqual
(
.
.
,
1
)
;
const
=
.
[
0
]
;
.
ok
(
.
includes
(
'rest'
)
)
;
.
ok
(
.
includes
(
'--method'
)
)
;
.
ok
(
.
includes
(
'patch'
)
)
;
.
ok
(
.
join
(
' '
)
.
includes
(
'88888'
)
)
;
.
ok
(
.
join
(
' '
)
.
includes
(
'api-version=7.0'
)
)
;
}
)
;
it
(
'list builds with filters constructs correct command'
,
async
(
)
=>
{
const
=
new
TestableAzureDevOpsClient
(
ORGANIZATION
,
PROJECT
)
;
await
.
listBuilds
(
'111'
,
{
:
'main'
,
:
'pullRequest'
,
:
10
}
)
;
.
strictEqual
(
.
.
,
1
)
;
const
=
.
[
0
]
;
.
ok
(
.
includes
(
'--branch'
)
)
;
.
ok
(
.
includes
(
'main'
)
)
;
.
ok
(
.
includes
(
'--reason'
)
)
;
.
ok
(
.
includes
(
'pullRequest'
)
)
;
.
ok
(
.
includes
(
'--top'
)
)
;
.
ok
(
.
includes
(
'10'
)
)
;
}
)
;
}
)
;
}
function
printMainUsage
(
)
:
void
{
const
=
'node .github/skills/azure-pipelines/azure-pipeline.ts'
;
console
.
log
(
` Usage: ${ scriptName} <command> [options] `
)
;
console
.
log
(
''
)
;
console
.
log
(
'Azure DevOps Pipeline CLI for VS Code builds.'
)
;
console
.
log
(
''
)
;
console
.
log
(
'Commands:'
)
;
console
.
log
(
' queue Queue a new pipeline build'
)
;
console
.
log
(
' status Check build status, list builds, download logs/artifacts'
)
;
console
.
log
(
' cancel Cancel a running build'
)
;
console
.
log
(
''
)
;
console
.
log
(
'Options:'
)
;
console
.
log
(
' --help Show help for a command'
)
;
console
.
log
(
' --tests Run the test suite'
)
;
console
.
log
(
''
)
;
console
.
log
(
'Examples:'
)
;
console
.
log
(
` ${ scriptName} queue # Queue build on current branch `
)
;
console
.
log
(
` ${ scriptName} status # List recent builds `
)
;
console
.
log
(
` ${ scriptName} status --build-id 123456 # Get build details `
)
;
console
.
log
(
` ${ scriptName} cancel --build-id 123456 # Cancel a build `
)
;
console
.
log
(
` ${ scriptName} --tests # Run test suite `
)
;
console
.
log
(
''
)
;
console
.
log
(
'Run any command with --help for detailed usage.'
)
;
}
async
function
main
(
)
:
Promise
<
void
>
{
const
=
.
.
slice
(
2
)
;
if
(
.
===
0
||
[
0
]
===
'--help'
||
[
0
]
===
'-h'
)
{
printMainUsage
(
)
;
.
exit
(
0
)
;
}
if
(
[
0
]
===
'--tests'
)
{
await
runAllTests
(
)
;
return
;
}
const
=
[
0
]
;
const
=
.
slice
(
1
)
;
switch
(
)
{
case
'queue'
:
await
runQueueCommand
(
)
;
break
;
case
'status'
:
await
runStatusCommand
(
)
;
break
;
case
'cancel'
:
await
runCancelCommand
(
)
;
break
;
default
:
console
.
error
(
.
red
(
` Error: Unknown command: ${ command} `
)
)
;
console
.
log
(
''
)
;
printMainUsage
(
)
;
.
exit
(
1
)
;
}
}
main
(
)
;