44 lines
1.8 KiB
PowerShell
44 lines
1.8 KiB
PowerShell
######### FUNZIONI COMUNI PER SCRIPT API GIT #########
|
|
|
|
#scrittura output & log
|
|
Function WriteLogOutput {
|
|
Param ($logFile, $logType, [string]$logString)
|
|
#compongo path per file di log
|
|
$logPath = Join-Path $logFolder $logFile
|
|
#scrivo su file la stringa se il tipo di log è > o uguale al livello richiesto
|
|
if ($logType -le $logLevel) {
|
|
Add-content $logPath -value "$logString"
|
|
#scrivo su terminale la stringa se $terminalOutput=1
|
|
if ($terminalOutput -eq 1) {
|
|
Write-Output($logString)
|
|
}
|
|
}
|
|
}
|
|
|
|
#creazione nuovo mirror
|
|
Function FreshMirrorCreation {
|
|
Param ($projectNumber, $user, $auth, $destination, $path)
|
|
#compongo url da chiamare per creazione nuovo mirror
|
|
$callUrlCreateMirror = "https://gitlab.steamware.net/api/v4/projects/" + $projectNumber + "/remote_mirrors"
|
|
#creo url del nuovo mirror con username e token relativi a gitlab
|
|
$newMirror = "https://" + $user + ":" + $auth + "@" + $destination + "/" + $path
|
|
#creo body da convertire in json
|
|
$body =
|
|
@{
|
|
url = $newMirror
|
|
enabled = 1
|
|
}
|
|
#converto body in json prima di passarlo alla chiamata POST
|
|
$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 $logFile 1 "NEW ID: $mirrorId - URL: $mirrorUrl - Mirror creato con successo"
|
|
} |