@@ -13,9 +13,13 @@ Parameter Accept = "application/vnd.github.v3+json";
13
13
14
14
Parameter Directory = " C:/temp/mirror/" ;
15
15
16
+ Parameter Username ;
17
+
18
+ Parameter Password ;
19
+
16
20
Property Request As %Net .HttpRequest [ Internal ];
17
21
18
- Method %OnNew (Username As %String = " " , Password As %String = " " ) As %Status [ Private , ServerOnly = 1 ]
22
+ Method %OnNew (Username As %String = {..#Username} , Password As %String = {..#Password} ) As %Status [ Private , ServerOnly = 1 ]
19
23
{
20
24
Quit ..CreateRequest (Username ,Password )
21
25
}
@@ -203,7 +207,6 @@ Method GetLastCommit(Owner As %String, Repository As %String, Branch As %String
203
207
204
208
Method MirrorAll (Directory As %String = {..#Directory}) As %Status
205
209
{
206
-
207
210
#Dim conf As %DynamicObject
208
211
#Dim repos As %DynamicArray
209
212
#Dim mirrors As %DynamicArray
@@ -229,7 +232,6 @@ Method MirrorAll(Directory As %String = {..#Directory}) As %Status
229
232
230
233
if (##class (%File ).Exists (Directory _repo )=1 )
231
234
{
232
- Do ..FetchAndPush (Directory _repo )
233
235
Continue
234
236
}
235
237
@@ -257,7 +259,7 @@ Method MirrorOne(Repo As %String, OwnerFrom As %String, OwnerTo As %String, Org
257
259
Set st1 = ..CreateRepo (Repo , description , $select (Org =0 :" " ,1 :OwnerTo ))
258
260
259
261
w " " _st1 ,!,!," Clone bare repo: " _sourceRepo
260
- Set st2 = $system . Status . DisplayError (.. Clone (sourceRepo , Directory ) )
262
+ Set st2 = .. Clone (sourceRepo , Directory )
261
263
Set st = $$$ADDSC(st1 , st2 )
262
264
263
265
w " " _st ,!,!," Mirroring: " _sourceRepo _" -> " _mirrorRepo
@@ -326,43 +328,21 @@ ClassMethod FetchAndPush(Directory As %String) As %Status
326
328
Return $$$ADDSC(st1 , st2 )
327
329
}
328
330
329
- // do ##class(GitHub.API).UpdateMirrors()
330
-
331
- ClassMethod UpdateMirrors (Directory As %String = {..#Directory}) As %Status
332
- {
333
- Set stream =##class (%Stream.FileCharacter ).%New ()
334
- Set st =stream .LinkToFile (Directory _" repos.json" )
335
- Set conf ={}.%FromJSON (stream .Read ($$$MaxCacheInt))
336
-
337
-
338
- Set mirrors = conf .mirrors
339
-
340
- For i =0 :1 :mirrors .%Size ()-1
341
- {
342
- set mirror = mirrors .%Get (i )
343
- Set repos = mirror .repos
344
-
345
- For i =0 :1 :repos .%Size ()-1
346
- {
347
- Set repo = repos .%Get (i )_" .git"
348
- Set st1 = ..FetchAndPush (Directory _repo )
349
- Set st = $$$ADDSC(st , st1 )
350
- }
351
- }
352
- Return st
353
- }
354
-
355
331
Method MirrorReleases (OwnerFrom As %String , OwnerTo As %String , Repo As %String ) As %Status
356
332
{
357
333
#Dim releases As %DynamicArray
358
334
#Dim release As %DynamicObject
359
335
360
336
Set st = ..GetReleasesList (OwnerFrom , Repo , .releases )
337
+ Set st = ..GetReleasesList (OwnerTo , Repo , .releasesTo )
338
+
339
+ set count = releases .Count ()-releasesTo .Count ()
361
340
362
- For i =1 :1 :releases .Count ()
341
+
342
+ For i =1 :1 :count
363
343
{
364
344
Set release = releases .GetAt (i )
365
-
345
+
366
346
Set st1 = ..CreateRelease (OwnerTo , Repo , release , .releaseid )
367
347
Set st = $$$ADDSC(st , st1 )
368
348
@@ -500,6 +480,56 @@ Method UploadAsset(Owner As %String, Repo As %String, ReleaseId As %Integer, Ass
500
480
return st
501
481
}
502
482
483
+ // do ##class(GitHub.API).UpdateMirrors()
484
+
485
+ ClassMethod UpdateMirrors (Username As %String = {..#Username}, Password As %String = {..#Password}, Directory As %String = {..#Directory}) As %Status
486
+ {
487
+ Set apiUM = ##class (GitHub.API ).%New (Username , Password )
488
+
489
+ Set stream = ##class (%Stream.FileCharacter ).%New ()
490
+ Set st = stream .LinkToFile (Directory _" repos.json" )
491
+ Set conf = {}.%FromJSON (stream .Read (stream .Size ))
492
+
493
+ Set mirrors = conf .mirrors
494
+
495
+ For i =0 :1 :mirrors .%Size ()-1
496
+ {
497
+ Set mirror = mirrors .%Get (i )
498
+ Set ownerfrom = mirror .from
499
+ Set ownerto = mirror .to
500
+ Set repos = mirror .repos
501
+
502
+ For j =0 :1 :repos .%Size ()-1
503
+ {
504
+ Set repo = repos .%Get (j )_" .git"
505
+
506
+ Set st1 = ..FetchAndPush (Directory _repo )
507
+ Set st = $$$ADDSC(st , st1 )
508
+
509
+ Set st1 = apiUM .MirrorReleases (ownerfrom , ownerto , $p (repo ," ." ,1 ))
510
+ Set st = $$$ADDSC(st , st1 )
511
+ }
512
+ }
513
+ Kill apiUM
514
+ Return st
515
+ }
516
+
517
+ ClassMethod UpdateMirrorReposInDirectory (Directory As %String = {..#Directory}) As %Status
518
+ {
519
+ Set rs = ##class (%File ).FileSetFunc (Directory ,,, 1 )
520
+
521
+ While rs .%Next ()
522
+ {
523
+ if rs .Type = " D"
524
+ {
525
+ Set repo = rs .Name
526
+ Set st1 = ..FetchAndPush (repo )
527
+ Set st = $$$ADDSC(st , st1 )
528
+ }
529
+ }
530
+ return st
531
+ }
532
+
503
533
Method test (test )
504
534
{
505
535
zw
0 commit comments