<# .SYNOPSIS Get or search a Gitea repository. .DESCRIPTION Three modes: -Name -> GET /repos/{owner}/{name} (default owner = auth user) -Search -> GET /repos/search?q= -List -> GET /repos/search (all visible to the token) .PARAMETER Owner Owner (user or org). Defaults to the authenticated user. .PARAMETER Name Exact repository name to look up. .PARAMETER Search Free-text search term. .PARAMETER List Switch: list all visible repos. .EXAMPLE .\Get-GiteaRepo.ps1 -Name Proxmox-Coolify-Manager .\Get-GiteaRepo.ps1 -Search manager .\Get-GiteaRepo.ps1 -List #> param( [string]$Owner, [Parameter(ParameterSetName = "ByName")] [string]$Name, [Parameter(ParameterSetName = "BySearch")] [string]$Search, [Parameter(ParameterSetName = "ListAll")] [switch]$List ) $ErrorActionPreference = "Stop" $here = Split-Path -Parent $MyInvocation.MyCommand.Path $api = Join-Path $here "Invoke-GiteaApi.ps1" function Resolve-GiteaOwner { param([string]$OwnerArg) if ($OwnerArg) { return $OwnerArg } $me = & $api -Path "/user" return $me.login } switch ($PSCmdlet.ParameterSetName) { "ByName" { if (-not $Name) { throw "Provide -Name." } $o = Resolve-GiteaOwner -OwnerArg $Owner try { $r = & $api -Path "/repos/$o/$Name" [PSCustomObject]@{ full_name = $r.full_name private = $r.private default_branch = $r.default_branch clone_url = $r.clone_url html_url = $r.html_url ssh_url = $r.ssh_url updated_at = $r.updated_at } | Format-List } catch { if ($_.Exception.Message -match "404") { Write-Host "Repository not found: $o/$Name" -ForegroundColor Yellow return } throw } } "BySearch" { $term = [uri]::EscapeDataString($Search) $r = & $api -Path "/repos/search?q=$term&limit=50" $r.data | Select-Object full_name, private, default_branch, updated_at | Format-Table -AutoSize } "ListAll" { $r = & $api -Path "/repos/search?limit=50" $r.data | Select-Object full_name, private, default_branch, updated_at | Format-Table -AutoSize } }