106 lines
4.2 KiB
PowerShell
106 lines
4.2 KiB
PowerShell
###Gitlab: Creazione repository su gitea###
|
|
|
|
#Questo script passa in rassegna tutti i progetti esistenti sul gitlab aziendale e per ognuno crea un repository con indirizzo semplice /egalware/nomeProgetto.git su gogs.
|
|
|
|
#importo file contenente configurazioni
|
|
. .\ApiGit\ApiGitResources\ApiScriptsConfig.ps1
|
|
#importo file contenente funzioni
|
|
. .\ApiGit\ApiGitResources\ApiScriptsFunctions.ps1
|
|
|
|
#rilevo time per log inizio analisi
|
|
$startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
|
# avvio stopwatch
|
|
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
|
#contatore ciclo do while
|
|
$projectCount = 200
|
|
#numero massimo di progetti da analizzare
|
|
$projectNumber = 300
|
|
#nome file di log
|
|
$logFile = "GogsReposCreation.log"
|
|
|
|
#creazione folder di Log se non già esistente
|
|
if (Test-Path $logFolder) {
|
|
}
|
|
else {
|
|
New-Item $logFolder -ItemType Directory
|
|
}
|
|
|
|
#chiedo all'utente il project ID su cui lavorare
|
|
#$projectCount = Read-Host -Prompt 'Project ID per eseguire lo script: '
|
|
|
|
#chiedo all'utente quante volte devo ciclare sui project ID
|
|
#$projectNumber = Read-Host -Prompt 'Contatore dei Project ID su cui lavorare: '
|
|
|
|
#scrivo intestazione e inizio analisi
|
|
WriteLogOutput $logFile 0 "--------------------"
|
|
Switch ($logLevel) {
|
|
0 { WriteLogOutput $logFile 0 "LOG SINTETICO GOGS" }
|
|
1 { WriteLogOutput $logFile 0 "LOG ERRORI GOGS" }
|
|
2 { WriteLogOutput $logFile 0 "LOG FULL GOGS" }
|
|
3 { WriteLogOutput $logFile 0 "LOG AMPOLLOSO GOGS" }
|
|
}
|
|
WriteLogOutput $logFile 0 ""
|
|
WriteLogOutput $logFile 0 "Percorso log: $logFolder"
|
|
WriteLogOutput $logFile 0 ""
|
|
WriteLogOutput $logFile 0 "Inizio Esecuzione Script: $startTime"
|
|
|
|
#ciclo principale do/while che cicla da 1 a N projectNumber
|
|
do {
|
|
$callGitlabUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount
|
|
try {
|
|
$gitlabResponse = Invoke-WebRequest -URI $callGitlabUrl -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
|
$parsedGitlabResponse = $gitlabResponse.Content | ConvertFrom-Json
|
|
#scrivo il numero del progetto nel terminale e su file
|
|
WriteLogOutput $logFile 1 ""
|
|
WriteLogOutput $logFile 1 "--------------------"
|
|
WriteLogOutput $logFile 1 "**PROGETTO $projectCount**"
|
|
foreach ($gitlabItem in $parsedGitlabResponse) {
|
|
WriteLogOutput $logFile 1 "Gitlab Project Name: $($gitlabItem.name)"
|
|
$callGogsUrl = "https://gogs.steamware.net/api/v1/admin/users/Egalware/repos"
|
|
#dichiaro un body da convertire in JSON con il nome del repo da creare
|
|
$gogsBody =
|
|
@{
|
|
name = $($gitlabItem.path);
|
|
#name = $($gitlabItem.name);
|
|
}
|
|
# Converting my hash to json format
|
|
$gogsJSON = $gogsBody | ConvertTo-Json
|
|
try {
|
|
$gogsResponse = Invoke-WebRequest -URI $callGogsUrl -Method POST -Headers $gogsHead -ContentType "application/json" -Body $gogsJSON
|
|
$parsedGogsResponse = $GogsResponse.Content | ConvertFrom-Json
|
|
foreach ($GogsItem in $parsedGogsResponse) {
|
|
WriteLogOutput $logFile 1 "Gogs New Project Name: $($gogsItem.name)"
|
|
}
|
|
}
|
|
catch {
|
|
$parsedError = $_ | ConvertFrom-Json
|
|
WriteLogOutput $logFile 3 $($parsedError.message)
|
|
}
|
|
}
|
|
}
|
|
#scrivo se trovo un errore durante il try/catch
|
|
catch {
|
|
$parsedError = $_ | ConvertFrom-Json
|
|
WriteLogOutput $logFile 3 ""
|
|
WriteLogOutput $logFile 3 "--------------------"
|
|
WriteLogOutput $logFile 3 "**ERRORE NEL PROGETTO $projectCount**"
|
|
WriteLogOutput $logFile 3 $($parsedError.message)
|
|
}
|
|
$projectCount = $projectCount + 1
|
|
}
|
|
#fine ciclo principale
|
|
while ($projectCount -le $projectNumber)
|
|
|
|
# fermo stopwatch e calcolo durata script
|
|
$mainStopWatch.Stop()
|
|
$durataScript = $mainStopWatch.Elapsed.TotalSeconds
|
|
|
|
#rilevo time per log fine analisi
|
|
$endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
|
|
|
#scrivo a video le statistiche
|
|
WriteLogOutput $logFile 0 ""
|
|
WriteLogOutput $logFile 0 "Fine Esecuzione Script: $endTime"
|
|
WriteLogOutput $logFile 0 ""
|
|
WriteLogOutput $logFile 0 "Durata Esecuzione Script: $durataScript secondi"
|
|
WriteLogOutput $logFile 0 "" |