Skip to content

Commit 6655c77

Browse files
committed
bugs fixed, update mirrors modified
1 parent a4bac62 commit 6655c77

File tree

1 file changed

+62
-32
lines changed

1 file changed

+62
-32
lines changed

src/cls/GitHub/API.cls

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ Parameter Accept = "application/vnd.github.v3+json";
1313

1414
Parameter Directory = "C:/temp/mirror/";
1515

16+
Parameter Username;
17+
18+
Parameter Password;
19+
1620
Property Request As %Net.HttpRequest [ Internal ];
1721

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 ]
1923
{
2024
Quit ..CreateRequest(Username,Password)
2125
}
@@ -203,7 +207,6 @@ Method GetLastCommit(Owner As %String, Repository As %String, Branch As %String
203207

204208
Method MirrorAll(Directory As %String = {..#Directory}) As %Status
205209
{
206-
207210
#Dim conf As %DynamicObject
208211
#Dim repos As %DynamicArray
209212
#Dim mirrors As %DynamicArray
@@ -229,7 +232,6 @@ Method MirrorAll(Directory As %String = {..#Directory}) As %Status
229232

230233
if (##class(%File).Exists(Directory_repo)=1)
231234
{
232-
Do ..FetchAndPush(Directory_repo)
233235
Continue
234236
}
235237

@@ -257,7 +259,7 @@ Method MirrorOne(Repo As %String, OwnerFrom As %String, OwnerTo As %String, Org
257259
Set st1 = ..CreateRepo(Repo, description, $select(Org=0:"",1:OwnerTo))
258260

259261
w " "_st1,!,!,"Clone bare repo: "_sourceRepo
260-
Set st2 = $system.Status.DisplayError(..Clone(sourceRepo, Directory))
262+
Set st2 = ..Clone(sourceRepo, Directory)
261263
Set st = $$$ADDSC(st1, st2)
262264

263265
w " "_st,!,!,"Mirroring: "_sourceRepo_" -> "_mirrorRepo
@@ -326,43 +328,21 @@ ClassMethod FetchAndPush(Directory As %String) As %Status
326328
Return $$$ADDSC(st1, st2)
327329
}
328330

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-
355331
Method MirrorReleases(OwnerFrom As %String, OwnerTo As %String, Repo As %String) As %Status
356332
{
357333
#Dim releases As %DynamicArray
358334
#Dim release As %DynamicObject
359335

360336
Set st = ..GetReleasesList(OwnerFrom, Repo, .releases)
337+
Set st = ..GetReleasesList(OwnerTo, Repo, .releasesTo)
338+
339+
set count = releases.Count()-releasesTo.Count()
361340

362-
For i=1:1:releases.Count()
341+
342+
For i=1:1:count
363343
{
364344
Set release = releases.GetAt(i)
365-
345+
366346
Set st1 = ..CreateRelease(OwnerTo, Repo, release, .releaseid)
367347
Set st = $$$ADDSC(st, st1)
368348

@@ -500,6 +480,56 @@ Method UploadAsset(Owner As %String, Repo As %String, ReleaseId As %Integer, Ass
500480
return st
501481
}
502482

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+
503533
Method test(test)
504534
{
505535
zw

0 commit comments

Comments
 (0)