Aggiornamento token & Script creatore di mondi
This commit is contained in:
@@ -6,8 +6,10 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
|
||||
#token per autenticazione
|
||||
$head = @{"PRIVATE-TOKEN"="glpat-dQsUhS-GxNomkh1GnjHZ"}
|
||||
#access token per autenticazione
|
||||
#creato da profilo marco.locatelli@egalware.com su gitlab.steamware.net
|
||||
#creazione 04 gennaio 2024, scadenza 31 dicembre 2024
|
||||
$head = @{"PRIVATE-TOKEN"="glpat-VjT_SAsBk3s-yWE1LDUF"}
|
||||
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
|
||||
@@ -6,8 +6,10 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
|
||||
#token per autenticazione
|
||||
$head = @{"PRIVATE-TOKEN"="glpat-dQsUhS-GxNomkh1GnjHZ"}
|
||||
#access token per autenticazione
|
||||
#creato da profilo marco.locatelli@egalware.com su gitlab.steamware.net
|
||||
#creazione 04 gennaio 2024, scadenza 31 dicembre 2024
|
||||
$head = @{"PRIVATE-TOKEN"="glpat-VjT_SAsBk3s-yWE1LDUF"}
|
||||
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
@@ -25,10 +27,10 @@ $mirrorErrorsCount = 0
|
||||
$mirrorSuccessCount = 0
|
||||
|
||||
#livello di log: 0=log sintetico, 1=log errori, 2=log full, 3=log ampolloso
|
||||
$logLevel = 0
|
||||
$logLevel = 2
|
||||
|
||||
#output a terminale: 0=disattivo, 1=abilitato
|
||||
$terminalOutput = 0
|
||||
$terminalOutput = 1
|
||||
|
||||
#cartella file di log
|
||||
$GitLogFolder="c:\Steamware\Logs\Gitlab\"
|
||||
@@ -93,13 +95,13 @@ do
|
||||
#verifico se i mirroring trovati per il progetto corrente hanno status "finished"
|
||||
if($item.update_status.Equals("finished"))
|
||||
{
|
||||
WriteLogOutput 2 "Mirror: $($item.url) - Status: $($item.update_status)"
|
||||
WriteLogOutput 2 "Mirror: $($item.url) - Status: $($item.update_status) - Last Success: $($item.last_successful_update_at)"
|
||||
$mirrorSuccessCount=$mirrorSuccessCount+1
|
||||
}
|
||||
#i mirroring che non hanno status "finished" vengono loggati con relativo errore
|
||||
else
|
||||
{
|
||||
WriteLogOutput 1 "Mirror: $($item.url) - Status: $($item.update_status)"
|
||||
WriteLogOutput 1 "Mirror: $($item.url) - Status: $($item.update_status) - Last Success: $($item.last_successful_update_at) - Last Attempt: $($item.last_update_started_at)"
|
||||
WriteLogOutput 1 "Error: $($item.last_error)"
|
||||
$mirrorErrorsCount=$mirrorErrorsCount+1
|
||||
}
|
||||
|
||||
@@ -10,8 +10,10 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
|
||||
#token per autenticazione
|
||||
$head = @{"PRIVATE-TOKEN"="glpat-dQsUhS-GxNomkh1GnjHZ"}
|
||||
#access token per autenticazione
|
||||
#creato da profilo marco.locatelli@egalware.com su gitlab.steamware.net
|
||||
#creazione 04 gennaio 2024, scadenza 31 dicembre 2024
|
||||
$head = @{"PRIVATE-TOKEN"="glpat-VjT_SAsBk3s-yWE1LDUF"}
|
||||
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
################START SCRIPT################
|
||||
|
||||
#rilevo time per log inizio analisi
|
||||
$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
|
||||
#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"}
|
||||
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 200
|
||||
|
||||
#livello di log: 0=log sintetico, 1=log errori, 2=log full, 3=log ampolloso
|
||||
$logLevel = 2
|
||||
|
||||
#output a terminale: 0=disattivo, 1=abilitato
|
||||
$terminalOutput = 1
|
||||
|
||||
#cartella file di log
|
||||
$GitLogFolder="C:\Steamware\Logs\Gitlab\"
|
||||
|
||||
#nome file di log
|
||||
$logFile = Join-Path $GitLogFolder "GiteaReposCreation.log"
|
||||
|
||||
#dichiaro funzione per scrittura output
|
||||
Function WriteLogOutput
|
||||
{
|
||||
Param ($logType, [string]$logString)
|
||||
#scrivo su file la stringa se il tipo di log è > o = al livello di log richieeso
|
||||
if($logType -le $logLevel)
|
||||
{
|
||||
Add-content $logFile -value "$logString"
|
||||
#scrivo su terminale la stringa se $terminalOutput=1
|
||||
if($terminalOutput -eq 1)
|
||||
{
|
||||
Write-Output($logString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $GitLogFolder)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
New-Item $GitLogFolder -ItemType Directory
|
||||
}
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput 0 "--------------------"
|
||||
Switch ($logLevel)
|
||||
{
|
||||
0 {WriteLogOutput 0 "LOG SINTETICO GITEA"}
|
||||
1 {WriteLogOutput 0 "LOG ERRORI GITEA"}
|
||||
2 {WriteLogOutput 0 "LOG FULL GITEA"}
|
||||
3 {WriteLogOutput 0 "LOG AMPOLLOSO GITEA"}
|
||||
}
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Percorso log: $GitLogFolder"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 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 1 ""
|
||||
WriteLogOutput 1 "--------------------"
|
||||
WriteLogOutput 1 "**PROGETTO $projectCount**"
|
||||
foreach($gitlabItem in $parsedGitlabResponse)
|
||||
{
|
||||
WriteLogOutput 1 "Gitlab Project Name: $($gitlabItem.name)"
|
||||
$callGiteaUrl = "https://gitea2.steamware.net/api/v1/orgs/Egalware/repos"
|
||||
#dichiaro un body da convertire in JSON con il nome del repo da creare
|
||||
$giteaBody =
|
||||
@{
|
||||
name = $($gitlabItem.name);
|
||||
}
|
||||
# Converting my hash to json format
|
||||
$GiteaJSON = $giteaBody | ConvertTo-Json
|
||||
try
|
||||
{
|
||||
$giteaResponse = Invoke-WebRequest -URI $callGiteaUrl -Method POST -Headers $giteaHead -ContentType "application/json" -Body $GiteaJSON
|
||||
$parsedGiteaResponse = $giteaResponse.Content | ConvertFrom-Json
|
||||
foreach($giteaItem in $parsedGiteaResponse)
|
||||
{
|
||||
WriteLogOutput 1 "Gitea New Project Name: $($giteaItem.name)"
|
||||
WriteLogOutput 1 "Status: $($giteaResponse.StatusDescription)"
|
||||
WriteLogOutput 1 "When: $($giteaItem.created_at)"
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#scrivo se trovo un errore (in particolare progetto non trovato) durante il try/catch (solo se loglevel è = 3)
|
||||
catch
|
||||
{
|
||||
WriteLogOutput 3 ""
|
||||
WriteLogOutput 3 "--------------------"
|
||||
WriteLogOutput 3 "**PROGETTO $projectCount NON ESISTENTE**"
|
||||
}
|
||||
$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 0 ""
|
||||
WriteLogOutput 0 "Fine Esecuzione Script: $endTime"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Durata Esecuzione Script: $durataScript secondi"
|
||||
WriteLogOutput 0 ""
|
||||
Reference in New Issue
Block a user