@@ -201,50 +201,89 @@ Method GetLastCommit(Owner As %String, Repository As %String, Branch As %String
201
201
Return st
202
202
}
203
203
204
- Method Mirror (Directory As %String = {..#Directory}) As %Status
204
+ Method MirrorAll (Directory As %String = {..#Directory}) As %Status
205
205
{
206
206
207
207
#Dim conf As %DynamicObject
208
208
#Dim repos As %DynamicArray
209
- Set github = " https://github.com/"
209
+ #Dim mirrors As %DynamicArray
210
+ #Dim st As %Status
210
211
211
- Set stream = ##class (%Stream.FileCharacter ).%New ()
212
- Set sc = stream .LinkToFile (Directory _" repos.json" )
213
- Set conf = {}.%FromJSON (stream .Read ($$$MaxCacheInt))
212
+ Set stream = ##class (%Stream.FileCharacter ).%New ()
213
+ Set st = stream .LinkToFile (Directory _" repos.json" )
214
+ Set conf = {}.%FromJSON (stream .Read ($$$MaxCacheInt))
214
215
215
- Set ownerfrom = conf .from
216
- Set ownerto = conf .to
217
- Set org = conf .org
218
- Set repos = conf .repos
216
+ set mirrors = conf .mirrors
219
217
220
- for i =0 :1 :repos .%Size ()-1
218
+ for i =0 :1 :mirrors .%Size ()-1
221
219
{
222
- Set repo = repos .%Get (i )_" .git"
220
+ set mirror = mirrors .%Get (i )
221
+ Set ownerfrom = mirror .from
222
+ Set ownerto = mirror .to
223
+ Set org = mirror .org
224
+ Set repos = mirror .repos
223
225
224
- if ( ##class ( %File ). Exists ( Directory _ repo )= 1 )
226
+ for j = 0 : 1 : repos . %Size ()- 1
225
227
{
226
- Do ..FetchAndPush (Directory _repo )
227
- Continue
228
+ Set repo = repos .%Get (j )_" .git"
229
+
230
+ if (##class (%File ).Exists (Directory _repo )=1 )
231
+ {
232
+ Do ..FetchAndPush (Directory _repo )
233
+ Continue
234
+ }
235
+
236
+ Set st1 = ..MirrorOne (repo , ownerfrom , ownerto , org )
237
+ Set st = $$$ADDSC(st , st1 )
238
+
228
239
}
229
-
230
- Do ..CreateRepo (repo , $select (org =0 :" " ,1 :ownerto ))
231
- Do ..Clone (github _ownerfrom _" /" _repo , Directory )
232
- Do ..Mirroring (Directory _repo , github _ownerto _" /" _repo )
233
- Do ..FetchAndPush (Directory _repo )
234
240
}
241
+ Return st
242
+ }
243
+
244
+ Method MirrorOne (Repo As %String , OwnerFrom As %String , OwnerTo As %String , Org As %String , Directory As %String = {..#Directory}) As %Status
245
+ {
246
+ Set st = $$$OK
247
+
248
+ Set github = " https://github.com/"
249
+ Set sourceRepo = github _OwnerFrom _" /" _Repo
250
+ Set mirrorRepo = github _OwnerTo _" /" _Repo
251
+
252
+ set description = " This is a read-only mirror of " _sourceRepo _" . Put you PR there."
253
+
254
+ w !," Create repo for mirroring: " _mirrorRepo
255
+ Set st1 = ..CreateRepo (Repo , description , $select (Org =0 :" " ,1 :OwnerTo ))
256
+
257
+ w " " _st1 ,!,!," Clone bare repo: " _sourceRepo
258
+ Set st2 = ..Clone (sourceRepo , Directory )
259
+ Set st = $$$ADDSC(st1 , st2 )
260
+
261
+ w " " _st ,!,!," Mirroring: " _sourceRepo _" -> " _mirrorRepo
262
+ Set st3 = ..Mirroring (Directory _Repo , mirrorRepo )
263
+ Set st = $$$ADDSC(st , st3 )
264
+
265
+ w " " _st ,!,!," Fetch and push... "
266
+ Set st4 = ..FetchAndPush (Directory _Repo )
267
+ Set st = $$$ADDSC(st , st4 )
268
+
269
+ Return st
235
270
}
236
271
237
- Method CreateRepo (Name As %String , Org As %String , Private As %String = " false" ) As %Status
272
+ Method CreateRepo (Name As %String , Description As %String = " empty " , Org As %String , Private As %String = " false" ) As %Status
238
273
{
239
274
if $d (Org ) && (Org '= " " ) {
240
275
Set ..Request .Location = " orgs/" _ Org _ " /repos"
241
276
}else {
242
277
Set ..Request .Location = " user/repos"
243
278
}
244
279
245
- Do ..Request .EntityBody .Write (" {" " name" " :" " " _Name _" " " ," " private" " :" _Private _" }" )
280
+ set json = " {" " name" " :" " " _Name _" " " ," " description" " :" " " _Description _" " " ," _
281
+ " " " private" " :" _Private _" , " " has_issues" " :false}"
282
+
283
+ Do ..Request .EntityBody .Write (json )
246
284
247
285
Set st = ..Request .Post ()
286
+
248
287
Return st
249
288
}
250
289
@@ -253,9 +292,9 @@ ClassMethod Clone(Repo As %String, Directory As %String, Parameter As %String =
253
292
Do $system .Process .CurrentDirectory (Directory )
254
293
Set cmd = " git clone " _ Parameter _" " _ Repo
255
294
256
- Do ##class (GitHub.Utils ).execute (cmd , 1 )
295
+ Set st = ##class (GitHub.Utils ).execute (cmd )
257
296
258
- Return $$$OK
297
+ Return st
259
298
}
260
299
261
300
ClassMethod Mirroring (Directory As %String , RepoForMirroring ) As %Status
@@ -264,24 +303,22 @@ ClassMethod Mirroring(Directory As %String, RepoForMirroring) As %Status
264
303
265
304
Set cmd = " git remote set-url --push origin " _ RepoForMirroring
266
305
267
- Do ##class (GitHub.Utils ).execute (cmd , 1 )
306
+ Set st = ##class (GitHub.Utils ).execute (cmd )
268
307
269
- Return $$$OK
308
+ Return st
270
309
}
271
310
272
311
ClassMethod FetchAndPush (Directory As %String ) As %Status
273
312
{
274
313
Do $system .Process .CurrentDirectory (Directory )
275
-
276
- Set st = $$$OK
277
-
314
+ w !!," directory: " _Directory ,!
278
315
Set cmd = " git fetch -p origin"
279
- Set st = ##class (GitHub.Utils ).execute (cmd ,1 )
316
+ Set st1 = ##class (GitHub.Utils ).execute (cmd ,1 )
280
317
281
318
Set cmd = " git push --mirror"
282
- Set st = ##class (GitHub.Utils ).execute (cmd ,1 )
319
+ Set st2 = ##class (GitHub.Utils ).execute (cmd ,1 )
283
320
284
- Return st
321
+ Return $$$ADDSC( st1 , st2 )
285
322
}
286
323
287
324
ClassMethod UpdateMirrors (Directory As %String = {..#Directory}) As %Status
0 commit comments