Creazione mirror mancanti verso gitea e gogs
This commit is contained in:
@@ -87,7 +87,7 @@ do
|
||||
foreach($gitlabItem in $parsedGitlabResponse)
|
||||
{
|
||||
WriteLogOutput 1 "Gitlab Project Name: $($gitlabItem.name)"
|
||||
$callGiteaUrl = "https://gitea2.steamware.net/api/v1/orgs/Egalware/repos"
|
||||
$callGiteaUrl = "https://gitea.steamware.net/api/v1/orgs/Egalware/repos"
|
||||
#dichiaro un body da convertire in JSON con il nome del repo da creare
|
||||
$giteaBody =
|
||||
@{
|
||||
|
||||
+36
-33
@@ -6,33 +6,18 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
|
||||
#access token per autenticazione
|
||||
#creato da profilo marco.locatelli@egalware.com su gitlab.steamware.net
|
||||
#access token per autenticazione creato da profilo marco.locatelli@egalware.com su gitlab.steamware.net
|
||||
#creazione 04 gennaio 2024, scadenza 31 dicembre 2024
|
||||
$gitlabHead = @{"PRIVATE-TOKEN"="glpat-VjT_SAsBk3s-yWE1LDUF"}
|
||||
|
||||
#access token per autenticazione
|
||||
#creato da profilo replica su gitea2.steamware.net
|
||||
#$giteaHead = @{"Authorization"="token 21c3e674ae369eda349d0e1fadaddd526f90419d"}
|
||||
$giteaPass = "ajejebrazorf92!"
|
||||
|
||||
#nome utente gitea che effettua i mirror push
|
||||
$giteaUser = "replica"
|
||||
|
||||
#password replcia gogs
|
||||
$gogsPass = "viaDante16!"
|
||||
|
||||
#nome utente gogs che effettua i mirror push
|
||||
$gogsUser = "replica"
|
||||
|
||||
#contatore ciclo do while
|
||||
$projectCount = 140
|
||||
$projectCount = 1
|
||||
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 1
|
||||
$projectNumber = 200
|
||||
|
||||
#livello di log: 0=log sintetico, 1=log errori, 2=log full, 3=log ampolloso
|
||||
$logLevel = 2
|
||||
$logLevel = 3
|
||||
|
||||
#output a terminale: 0=disattivo, 1=abilitato
|
||||
$terminalOutput = 1
|
||||
@@ -77,11 +62,14 @@ Function FreshMirrorCreation
|
||||
$jsonBody = ConvertTo-Json -InputObject $body
|
||||
#chiamata api POST che crea mirror con url e body specificati
|
||||
$rebuildResponse = Invoke-WebRequest -Method Post -URI $callUrlCreateMirror -Headers $gitlabHead -ContentType "application/json" -Body $jsonBody -UseBasicParsing
|
||||
#conversione da Json della risposta alla chiamata POST
|
||||
$parsedRebuild = $rebuildResponse.Content | ConvertFrom-Json
|
||||
#rilevo ID e URL nuovo mirror per scriverli nel log
|
||||
foreach($item in $parsedRebuild){
|
||||
$mirrorId = $($item.id)
|
||||
$mirrorUrl = $($item.url)
|
||||
}
|
||||
#scrivo ID e URL nuovo mirror
|
||||
WriteLogOutput 1 "NEW ID: $mirrorId - URL: $mirrorUrl - Mirror creato con successo"
|
||||
}
|
||||
|
||||
@@ -120,21 +108,36 @@ do
|
||||
WriteLogOutput 1 ""
|
||||
WriteLogOutput 1 "--------------------"
|
||||
WriteLogOutput 1 "**PROGETTO $projectCount**"
|
||||
if($gitlabResponse.Content -eq "[]")
|
||||
#ricavo nome del progetto per poter creare mirror
|
||||
$nameCall = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount
|
||||
$nameResponse = Invoke-WebRequest -URI $nameCall -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||
$parsedNameResponse = $nameResponse.Content | ConvertFrom-Json
|
||||
$repoPath = $($parsedNameResponse.path)
|
||||
#compongo path con struttura Egalware/NomeProgetto.git
|
||||
$path = "Egalware/" + $repoPath + ".git"
|
||||
#se la risposta non contiene "gitea" procedo a creare mirror relativo
|
||||
if($gitlabResponse.Content -inotmatch "gitea")
|
||||
{
|
||||
$callUrl2 = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount
|
||||
$gitlabResponse2 = Invoke-WebRequest -URI $callUrl2 -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||
$parsedResponse2 = $gitlabResponse2.Content | ConvertFrom-Json
|
||||
$repoPath = $($parsedResponse2.path)
|
||||
$path = "Egalware/" + $repoPath + ".git"
|
||||
try
|
||||
{
|
||||
FreshMirrorCreation $projectCount $giteaUser $giteaPass "@gitea2.steamware.net" $path
|
||||
FreshMirrorCreation $projectCount $gogsUser $gogsPass "@gogs.steamware.net" $path
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
#autenticazione replica gitea
|
||||
$giteaPass = "ajejebrazorf92!"
|
||||
#nome utente gitea che effettua i mirror push
|
||||
$giteaUser = "replica"
|
||||
#destinazione mirror per gitea
|
||||
$giteaDestination = "@gitea.steamware.net"
|
||||
#chiamo funzione per creare mirror verso gitea
|
||||
FreshMirrorCreation $projectCount $giteaUser $giteaPass $giteaDestination $path
|
||||
}
|
||||
#se la risposta non contiene "gogs" procedo a creare mirror relativo
|
||||
if($gitlabResponse.Content -inotmatch "gogs")
|
||||
{
|
||||
#password replica gogs
|
||||
$gogsPass = "viaDante16!"
|
||||
#nome utente gogs che effettua i mirror push
|
||||
$gogsUser = "replica"
|
||||
#destinazione mirror per gogs
|
||||
$gogsDestination = "@gogs.steamware.net"
|
||||
#chiamo funzione per creare mirror verso gogs
|
||||
FreshMirrorCreation $projectCount $gogsUser $gogsPass $gogsDestination $path
|
||||
}
|
||||
}
|
||||
#scrivo se trovo un errore (in particolare progetto non trovato) durante il try/catch (solo se loglevel è = 3)
|
||||
@@ -12,7 +12,7 @@ $mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
$gitlabHead = @{"PRIVATE-TOKEN"="glpat-VjT_SAsBk3s-yWE1LDUF"}
|
||||
|
||||
#access token per autenticazione
|
||||
#creato da profilo replica su gitea2.steamware.net
|
||||
#creato da profilo replica su gitea.steamware.net
|
||||
#$giteaHead = @{"Authorization"="token 21c3e674ae369eda349d0e1fadaddd526f90419d"}
|
||||
$giteaPass = "ajejebrazorf92!"
|
||||
|
||||
@@ -97,20 +97,14 @@ do
|
||||
WriteLogOutput 1 "**PROGETTO $projectCount**"
|
||||
foreach($item in $parsedResponse)
|
||||
{
|
||||
$doExecute = "false"
|
||||
$token = ""
|
||||
$mirrorUrl = ""
|
||||
$trunkedPath = ""
|
||||
#controllo se l'url del mirror contiene gitea
|
||||
if($item.url.Contains("gitea"))
|
||||
{
|
||||
$doExecute = "true"
|
||||
$token = $giteaPass
|
||||
$mirrorDestination = "@gitea2.steamware.net"
|
||||
}
|
||||
#verifico se devo effettuare cancellazione e creazione nuovo mirror
|
||||
if($doExecute -eq "true")
|
||||
{
|
||||
$mirrorDestination = "@gitea.steamware.net"
|
||||
#salvo id mirror e url mirror
|
||||
$mirrorId = $($item.id)
|
||||
$mirrorUrl = $($item.url)
|
||||
|
||||
Reference in New Issue
Block a user