From db58ee6f6bcef58525a20211ae5c7956eebf1f0f Mon Sep 17 00:00:00 2001 From: "marco.locatelli@steamware.net" Date: Mon, 8 Jan 2024 16:08:25 +0100 Subject: [PATCH] Creazione mirror mancanti verso gitea e gogs --- Gitlab API/GiteaReposCreation.ps1 | 2 +- ....ps1 => GitlabCreateMirrorToGogsGitea.ps1} | 69 ++++++++++--------- ...bMirroring.ps1 => GitlabMirrorRenewal.ps1} | 0 Gitlab API/GitlabMirroringToGitea.ps1 | 10 +-- 4 files changed, 39 insertions(+), 42 deletions(-) rename Gitlab API/{GitlabNewMirrorCreation.ps1 => GitlabCreateMirrorToGogsGitea.ps1} (69%) rename Gitlab API/{RenewGitlabMirroring.ps1 => GitlabMirrorRenewal.ps1} (100%) diff --git a/Gitlab API/GiteaReposCreation.ps1 b/Gitlab API/GiteaReposCreation.ps1 index c408d76..eb6521f 100644 --- a/Gitlab API/GiteaReposCreation.ps1 +++ b/Gitlab API/GiteaReposCreation.ps1 @@ -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 = @{ diff --git a/Gitlab API/GitlabNewMirrorCreation.ps1 b/Gitlab API/GitlabCreateMirrorToGogsGitea.ps1 similarity index 69% rename from Gitlab API/GitlabNewMirrorCreation.ps1 rename to Gitlab API/GitlabCreateMirrorToGogsGitea.ps1 index ddca4d6..37d5358 100644 --- a/Gitlab API/GitlabNewMirrorCreation.ps1 +++ b/Gitlab API/GitlabCreateMirrorToGogsGitea.ps1 @@ -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) diff --git a/Gitlab API/RenewGitlabMirroring.ps1 b/Gitlab API/GitlabMirrorRenewal.ps1 similarity index 100% rename from Gitlab API/RenewGitlabMirroring.ps1 rename to Gitlab API/GitlabMirrorRenewal.ps1 diff --git a/Gitlab API/GitlabMirroringToGitea.ps1 b/Gitlab API/GitlabMirroringToGitea.ps1 index d641b8f..23d965f 100644 --- a/Gitlab API/GitlabMirroringToGitea.ps1 +++ b/Gitlab API/GitlabMirroringToGitea.ps1 @@ -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)