# Apply branch protection to all repos in an organization param( [string]$ApiToken = $env:GITEA_TOKEN, [string]$GiteaBaseUrl = "http://afe.git:3000", [string]$Org, [string]$BranchName, [ValidateSet("lock", "unlock")] [string]$Action = "lock" ) $ErrorActionPreference = "Stop" $ConfigPath = Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Path) "..\config.local.json" if (-not $ApiToken -and (Test-Path $ConfigPath)) { $cfg = Get-Content $ConfigPath -Raw | ConvertFrom-Json $ApiToken = $cfg.ApiToken if ($cfg.GiteaBaseUrl) { $GiteaBaseUrl = $cfg.GiteaBaseUrl } } if (-not $ApiToken) { Write-Host "Error: ApiToken required"; exit 1 } if (-not $Org -or -not $BranchName) { Write-Host "Error: Org, BranchName required"; exit 1 } $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $BranchScript = Join-Path $ScriptDir "branch_protect.ps1" $repos = @(& "$ScriptDir\list_orgs_repos.ps1" -ApiToken $ApiToken -GiteaBaseUrl $GiteaBaseUrl -Action list-repos -Org $Org) if (-not $repos -or $repos.Count -eq 0) { Write-Host "No repos found in org $Org"; exit 0 } $count = 0 foreach ($r in $repos) { if (-not $r) { continue } Write-Host "Processing $Org/$r..." & $BranchScript -ApiToken $ApiToken -GiteaBaseUrl $GiteaBaseUrl -Owner $Org -Repo $r -BranchName $BranchName -Action $Action $count++ } Write-Host "Done. Processed $count repos."