67 lines
2.8 KiB
PowerShell
67 lines
2.8 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Ermittelt das nächste offene Ticket aus Forgejo (via status:todo Label).
|
|
.DESCRIPTION
|
|
Sortierung: priority:high (0) → normal (1) → priority:low (2), dann Issue-Nummer aufsteigend.
|
|
Gibt Nummer, Typ-Label, Titel und Order (= Issue-Nummer) aus.
|
|
.PARAMETER IssueNumber
|
|
Optional: Direkt eine Issue-Nummer abfragen statt automatischer Suche.
|
|
#>
|
|
param([int]$IssueNumber)
|
|
|
|
$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" }
|
|
|
|
function Get-IssueType($labelNames) {
|
|
if ($labelNames -contains "block-planning") { "[B]" }
|
|
elseif ($labelNames -contains "migration") { "[M]" }
|
|
elseif ($labelNames -contains "feature") { "[F]" }
|
|
elseif ($labelNames -contains "refactoring") { "[F]" }
|
|
elseif ($labelNames -contains "tech-decision") { "[T]" }
|
|
elseif ($labelNames -contains "infrastructure") { "[I]" }
|
|
elseif ($labelNames -contains "planning") { "[P]" }
|
|
elseif ($labelNames -contains "test") { "[X]" }
|
|
else { "[?]" }
|
|
}
|
|
|
|
if ($IssueNumber -gt 0) {
|
|
# Variante A: Explizite Issue-Nummer → Forgejo REST API
|
|
$url = "$forgejoBase/repos/$repo/issues/$IssueNumber"
|
|
$issue = (Invoke-WebRequest -Uri $url -Headers $headers -UseBasicParsing).Content | ConvertFrom-Json
|
|
$labelNames = $issue.labels | ForEach-Object { $_.name }
|
|
$type = Get-IssueType $labelNames
|
|
Write-Host "#$($issue.number) $type $($issue.title)"
|
|
}
|
|
else {
|
|
# Variante B: Nächstes Ticket per Forgejo-Label status:todo
|
|
$url = "$forgejoBase/repos/$repo/issues?state=open&type=issues&labels=status%3Atodo&limit=50&sort=oldest"
|
|
$issues = (Invoke-WebRequest -Uri $url -Headers $headers -UseBasicParsing).Content | ConvertFrom-Json
|
|
if ($null -eq $issues -or $issues.Count -eq 0) {
|
|
Write-Host "Keine offenen Tickets mit 'status:todo' gefunden."
|
|
return
|
|
}
|
|
$todos = $issues | ForEach-Object {
|
|
$labelNames = $_.labels | ForEach-Object { $_.name }
|
|
$prio = if ($labelNames -contains "priority:high") { 0 }
|
|
elseif ($labelNames -contains "priority:low") { 2 }
|
|
else { 1 }
|
|
$type = Get-IssueType $labelNames
|
|
[PSCustomObject]@{
|
|
Number = $_.number
|
|
Title = $_.title
|
|
Order = $_.number # Issue-Nummer als Tiebreaker (aufsteigend = älteste zuerst)
|
|
Prio = $prio
|
|
Type = $type
|
|
}
|
|
} | Sort-Object Prio, Order | Select-Object -First 1
|
|
|
|
if ($todos) {
|
|
Write-Host "#$($todos.Number) $($todos.Type) $($todos.Title) (Order: $($todos.Order))"
|
|
}
|
|
else {
|
|
Write-Host "Keine offenen Tickets gefunden."
|
|
}
|
|
}
|