<# .SYNOPSIS Setzt den Status eines Issues in Forgejo via Label (status:todo / status:in-progress / status:done / status:backlog). .DESCRIPTION Entfernt alle status:*-Labels und setzt das neue Status-Label. Akzeptierte Werte: "Todo", "InProgress" (oder "In Progress"), "Done", "Backlog". .PARAMETER IssueNumber Die Issue-Nummer (z.B. 68). .PARAMETER Status Der Zielstatus: "Todo", "InProgress", "In Progress", "Done" oder "Backlog". #> param( [Parameter(Mandatory)][int]$IssueNumber, [Parameter(Mandatory)][string]$Status ) $forgejoBase = "https://git.bollwerk.online/api/v1" $repo = "bollwerkadmin/bollwerk" $tokenFile = Join-Path $PSScriptRoot "forgejo-token.txt" $token = (Get-Content $tokenFile -Raw -ErrorAction Stop).Trim() $headers = @{ Authorization = "token $token"; "Content-Type" = "application/json" } # Normalisierung $normalizedStatus = $Status.Trim() -replace '\s+', '' $labelMap = @{ "Todo" = "status:todo" "InProgress" = "status:in-progress" "Done" = "status:done" "Backlog" = "status:backlog" } if (-not $labelMap.ContainsKey($normalizedStatus)) { $valid = $labelMap.Keys -join ", " Write-Error "Ungültiger Status '$Status'. Gültige Werte: $valid (auch 'In Progress' für InProgress)." exit 1 } $newLabel = $labelMap[$normalizedStatus] # Alle Labels des Issues abrufen $issueUrl = "$forgejoBase/repos/$repo/issues/$IssueNumber" $issue = (Invoke-WebRequest -Uri $issueUrl -Headers $headers -UseBasicParsing).Content | ConvertFrom-Json # Alte status:*-Labels entfernen $statusLabelIds = $issue.labels | Where-Object { $_.name -like "status:*" } | ForEach-Object { $_.id } foreach ($id in $statusLabelIds) { Invoke-WebRequest -Uri "$forgejoBase/repos/$repo/issues/$IssueNumber/labels/$id" -Method Delete -Headers $headers -UseBasicParsing | Out-Null } # Neues Status-Label-ID ermitteln $allLabels = (Invoke-WebRequest -Uri "$forgejoBase/repos/$repo/labels?limit=50" -Headers $headers -UseBasicParsing).Content | ConvertFrom-Json $targetLabel = $allLabels | Where-Object { $_.name -eq $newLabel } | Select-Object -First 1 if (-not $targetLabel) { Write-Error "Label '$newLabel' nicht auf Forgejo gefunden. Bitte zuerst anlegen." exit 1 } # Neues Status-Label setzen $body = "{`"labels`":[" + $targetLabel.id + "]}" Invoke-WebRequest -Uri "$forgejoBase/repos/$repo/issues/$IssueNumber/labels" -Method Post -Headers $headers -Body $body -UseBasicParsing | Out-Null Write-Host "Issue #$IssueNumber → $normalizedStatus"