Files
Proxmox-Coolify-Manager/gitea_skill/scripts/Test-GiteaConnection.ps1
T

69 lines
2.3 KiB
PowerShell

<#
.SYNOPSIS
Gitea smoke test: config + API auth + token scopes.
.DESCRIPTION
Calls /version, /user (auth), /settings/api, and lists the authenticated
user's repos. Exits 1 on any FAIL so it composes into CI / agent startup.
.EXAMPLE
.\Test-GiteaConnection.ps1
#>
$ErrorActionPreference = "Stop"
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$api = Join-Path $here "Invoke-GiteaApi.ps1"
if ([string]::IsNullOrWhiteSpace($env:GITEA_TOKEN)) {
Write-Host "[FAIL] GITEA_TOKEN not set. Load .\.env.local.ps1 first." -ForegroundColor Red
exit 1
}
if ([string]::IsNullOrWhiteSpace($env:GITEA_URL)) {
Write-Host "[WARN] GITEA_URL not set; using default https://gitea-hjwh0svsoo9p5w5kj2j6b1bd.urieljareth.org" -ForegroundColor Yellow
}
$failures = 0
# 1) Version (anonymous, but proves reachability)
try {
$v = & $api -Path "/version"
Write-Host "[PASS] /version -> Gitea $($v.version)" -ForegroundColor Green
} catch {
Write-Host "[FAIL] /version: $($_.Exception.Message)" -ForegroundColor Red
$failures++
}
# 2) Authenticated user (proves token validity)
try {
$u = & $api -Path "/user"
Write-Host "[PASS] /user -> login='$($u.login)' is_admin=$($u.is_admin)" -ForegroundColor Green
} catch {
Write-Host "[FAIL] /user (token invalid or expired): $($_.Exception.Message)" -ForegroundColor Red
$failures++
}
# 3) Token scopes (Gitea 1.20+: /users/me/tokens only lists tokens created via API; for app tokens, /user suffices)
try {
$settings = & $api -Path "/settings/api"
Write-Host "[PASS] /settings/api -> max_response_items=$($settings.max_response_items)" -ForegroundColor Green
} catch {
Write-Host "[WARN] /settings/api unavailable on this version: $($_.Exception.Message)" -ForegroundColor Yellow
}
# 4) List repos (proves read scope on /repos/search)
try {
$repos = & $api -Path "/repos/search?limit=50"
$count = @($repos.data).Count
Write-Host "[PASS] /repos/search -> $count repos visible" -ForegroundColor Green
} catch {
Write-Host "[FAIL] /repos/search: $($_.Exception.Message)" -ForegroundColor Red
$failures++
}
Write-Host ""
if ($failures -gt 0) {
Write-Host "[RESULT] $failures FAIL(s). Gitea skill NOT ready." -ForegroundColor Red
exit 1
}
Write-Host "[RESULT] OK. Gitea skill ready." -ForegroundColor Green