bollwerk/.github/skills/gh-tickets/create-next-ticket.ps1

75 lines
2.5 KiB
PowerShell

<#
.SYNOPSIS
Erstellt ein neues GitHub-Issue und setzt es als nächstes Ticket im Board.
.DESCRIPTION
Legt ein Issue an, fügt es zum Project Board hinzu und setzt den Order-Wert
auf den niedrigsten aller offenen (nicht-Done) Items minus 1.
Dadurch wird es automatisch das nächste abzuarbeitende Ticket.
.PARAMETER Title
Titel des neuen Issues.
.PARAMETER Body
Body-Text des Issues (Markdown). Optional, Default: leer.
.PARAMETER Labels
Komma-separierte Labels (z.B. "migration,crm,enhancement"). Muss mindestens
ein Type-Label enthalten: migration, tech-decision oder infrastructure.
#>
param(
[Parameter(Mandatory)][string]$Title,
[string]$Body = "",
[Parameter(Mandatory)][string]$Labels
)
$repo = "jreinemann-euris/kispielwiese"
$projectId = "PVT_kwHOCFqiJ84BWFbQ"
$orderFieldId = "PVTF_lAHOCFqiJ84BWFbQzhRi30o"
# --- 1. Type-Label validieren ---
$labelList = $Labels -split ',' | ForEach-Object { $_.Trim() }
$hasType = ($labelList -contains "migration") -or ($labelList -contains "tech-decision") -or ($labelList -contains "infrastructure")
if (-not $hasType) {
Write-Error "Mindestens ein Type-Label erforderlich: migration, tech-decision, infrastructure"
exit 1
}
# --- 2. Issue anlegen ---
$createArgs = @("issue", "create", "--repo", $repo, "--title", $Title, "--label", $Labels)
if ($Body) {
$createArgs += "--body"
$createArgs += $Body
}
$issueUrl = & gh @createArgs 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Error "Fehler beim Anlegen des Issues: $issueUrl"
exit 1
}
$issueNumber = ($issueUrl -split '/')[-1]
# --- 3. Zum Board hinzufügen ---
$addResult = gh project item-add 1 --owner jreinemann-euris --url $issueUrl --format json 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Error "Fehler beim Hinzufügen zum Board: $addResult"
exit 1
}
$itemId = ($addResult | ConvertFrom-Json).id
# --- 4. Niedrigsten Order-Wert ermitteln ---
$raw = gh project item-list 1 --owner jreinemann-euris --format json --limit 200 | ConvertFrom-Json
$minOrder = $raw.items |
Where-Object { $_.status -ne "Done" -and $_.id -ne $itemId } |
ForEach-Object { [double]$_.order } |
Where-Object { $_ -gt 0 } |
Measure-Object -Minimum |
Select-Object -ExpandProperty Minimum
if ($null -eq $minOrder) { $minOrder = 10 }
$newOrder = $minOrder - 1
# --- 5. Order setzen ---
gh project item-edit --project-id $projectId --id $itemId --field-id $orderFieldId --number $newOrder 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Error "Fehler beim Setzen des Order-Werts."
exit 1
}
Write-Host "#$issueNumber $Title (Order: $newOrder)"