<# .SYNOPSIS Erstellt ein neues Issue auf Forgejo und setzt das Status-Label. .DESCRIPTION Legt ein Issue an und setzt ein Status-Label (status:todo oder status:backlog). Die Reihenfolge ergibt sich aus der Issue-Nummer (aufsteigend = ältere zuerst). - Status "Todo" (Standard): Label status:todo → wird als nächstes Ticket gefunden. - Status "Backlog": Label status:backlog → wird erst nach Todo-Items bearbeitet. .PARAMETER Title Titel des neuen Issues. .PARAMETER Body Body-Text des Issues (Markdown). Optional, Default: leer. .PARAMETER Labels Komma-separierte Labels (z.B. "infrastructure,enhancement"). Muss mindestens ein Type-Label enthalten: migration, tech-decision, infrastructure, block-planning, feature, refactoring, planning oder test. .PARAMETER Status Status des neuen Tickets: "Todo" (Standard) oder "Backlog". #> param( [Parameter(Mandatory)][string]$Title, [string]$Body = "", [Parameter(Mandatory)][string]$Labels, [ValidateSet("Todo", "Backlog")] [string]$Status = "Todo" ) $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" } $statusLabelMap = @{ "Todo" = "status:todo" "Backlog" = "status:backlog" } # --- 1. Type-Label validieren --- $labelList = $Labels -split ',' | ForEach-Object { $_.Trim() } $validTypes = @("migration","tech-decision","infrastructure","block-planning","feature","refactoring","planning","test") $hasType = ($labelList | Where-Object { $validTypes -contains $_ }).Count -gt 0 if (-not $hasType) { Write-Error "Mindestens ein Type-Label erforderlich: $($validTypes -join ', ')" exit 1 } # --- 2. Alle Label-Namen zu IDs auflösen --- $allLabels = (Invoke-WebRequest -Uri "$forgejoBase/repos/$repo/labels?limit=50" -Headers $headers -UseBasicParsing).Content | ConvertFrom-Json $statusLabelName = $statusLabelMap[$Status] $allRequiredLabels = $labelList + $statusLabelName $labelIds = @() foreach ($name in $allRequiredLabels) { $found = $allLabels | Where-Object { $_.name -eq $name } | Select-Object -First 1 if ($found) { $labelIds += $found.id } else { Write-Warning "Label '$name' nicht gefunden – wird übersprungen." } } # --- 3. Issue anlegen --- $issueBody = @{ title = $Title; labels = $labelIds } if ($Body) { $issueBody["body"] = $Body } $issueJson = $issueBody | ConvertTo-Json $issueResp = Invoke-WebRequest -Uri "$forgejoBase/repos/$repo/issues" -Method Post -Headers $headers -Body $issueJson -UseBasicParsing $issue = $issueResp.Content | ConvertFrom-Json $issueNumber = $issue.number $issueUrl = $issue.html_url Write-Host "#$issueNumber $Title (Status: $Status)" Write-Host "URL: $issueUrl"