Repository: dotnet/runtime
File: .github/skills/vmr-codeflow-status/scripts/Get-CodeflowStatus.ps1 (PowerShell)

Code before:

if ($forcePushEvents.Count -gt 0) {
    foreach ($fp in $forcePushEvents) {
        $fpActor = if ($fp.actor) { $fp.actor.login } else { "unknown" }
        $fpTime = $fp.created_at
        $fpSha = if ($fp.commit_id) { Get-ShortSha $fp.commit_id } else { "unknown" }
        Write-Host "  🔄 Force push by @$fpActor at $fpTime (→ $fpSha)" -ForegroundColor Cyan
    }
    $lastForcePush = $forcePushEvents[-1]
    $lastForcePushTime = if ($lastForcePush.created_at) {
        [DateTimeOffset]::Parse($lastForcePush.created_at).UtcDateTime
    } else { $null }
    $lastForcePushActor = if ($lastForcePush.actor) { $lastForcePush.actor.login } else { "unknown" }
}

# Synthesize current state assessment
$prUpdatedTime = if ($pr.updatedAt) { [DateTimeOffset]::Parse($pr.updatedAt).UtcDateTime } else { $null }
$prAgeDays = if ($prUpdatedTime) { ([DateTime]::UtcNow - $prUpdatedTime).TotalDays } else { 0 }
$isClosed = $pr.state -eq "CLOSED"
$isMerged = $pr.state -eq "MERGED"
$currentState = if ($isMerged) {
    "MERGED"
} elseif ($isClosed) {
    "CLOSED"
} elseif ($isEmptyDiff -and $forcePushEvents.Count -gt 0) {
    "NO-OP"
} elseif ($isEmptyDiff) {
    "NO-OP"
} elseif ($forcePushEvents.Count -gt 0 -and $lastForcePushTime -and ([DateTime]::UtcNow - $lastForcePushTime).TotalHours -lt 24) {
    "IN_PROGRESS"
} elseif ($prAgeDays -gt 3) {
    "STALE"
} else {
    "ACTIVE"
}

Write-Host ""
switch ($currentState) {
    "MERGED"      { Write-Host "  ✅ MERGED — PR has been merged" -ForegroundColor Green }
    "CLOSED"      { Write-Host "  ✖️  CLOSED — PR was closed without merging" -ForegroundColor DarkGray }
    "NO-OP"       { Write-Host "  📭 NO-OP — empty diff, likely already resolved" -ForegroundColor Yellow }
    "IN_PROGRESS" { Write-Host "  🔄 IN PROGRESS — recent force push, awaiting update" -ForegroundColor Cyan }
    "STALE"       { Write-Host "  ⏳ STALE — no recent activity" -ForegroundColor Yellow }
    "ACTIVE"      { Write-Host "  ✅ ACTIVE — PR has content" -ForegroundColor Green }
}

# --- Step 3: Codeflow Metadata ---
Write-Section "Codeflow Metadata"

$body = $pr.body


Review comment (refactor):
The condition on line 706 is redundant with line 708. Both return "NO-OP", and the first condition is a strict subset of the second (if isEmptyDiff is true, we return NO-OP regardless of force push count). Consider simplifying to just one elseif clause checking isEmptyDiff.
```suggestion

```

Code after:
try {
    $timelineJson = gh api "repos/$owner/$repo/issues/$PRNumber/timeline" --paginate --slurp --jq 'map(.[] | select(.event == "head_ref_force_pushed"))' 2>$null
    if ($LASTEXITCODE -eq 0 -and $timelineJson) {
        $forcePushEvents = @($timelineJson | ConvertFrom-Json)
        $forcePushFetchSucceeded = $true
    } elseif ($LASTEXITCODE -ne 0) {
        Write-Warning "Could not fetch PR timeline for force push detection (gh api exit code $LASTEXITCODE). Current state assessment may be incomplete."
    } else {
        $forcePushFetchSucceeded = $true
    }
}
catch {
    Write-Warning "Failed to parse timeline JSON for force push events: $($_.Exception.Message)"
    $forcePushEvents = @()
}

if ($forcePushEvents.Count -gt 0) {
    foreach ($fp in $forcePushEvents) {
        $fpActor = if ($fp.actor) { $fp.actor.login } else { "unknown" }
        $fpTime = $fp.created_at
        $fpSha = if ($fp.commit_id) { Get-ShortSha $fp.commit_id } else { "unknown" }
        Write-Host "  🔄 Force push by @$fpActor at $fpTime (→ $fpSha)" -ForegroundColor Cyan
    }
    $lastForcePush = $forcePushEvents[-1]
    $lastForcePushTime = if ($lastForcePush.created_at) {
        [DateTimeOffset]::Parse($lastForcePush.created_at).UtcDateTime
    } else { $null }
    $lastForcePushActor = if ($lastForcePush.actor) { $lastForcePush.actor.login } else { "unknown" }
}

# Synthesize current state assessment
$prUpdatedTime = if ($pr.updatedAt) { [DateTimeOffset]::Parse($pr.updatedAt).UtcDateTime } else { $null }
$prAgeDays = if ($prUpdatedTime) { ([DateTime]::UtcNow - $prUpdatedTime).TotalDays } else { 0 }
$isClosed = $pr.state -eq "CLOSED"
$isMerged = $pr.state -eq "MERGED"
$currentState = if ($isMerged) {
    "MERGED"
} elseif ($isClosed) {
    "CLOSED"
} elseif ($isEmptyDiff) {
    "NO-OP"
} elseif ($forcePushEvents.Count -gt 0 -and $lastForcePushTime -and ([DateTime]::UtcNow - $lastForcePushTime).TotalHours -lt 24) {
    "IN_PROGRESS"
} elseif ($prAgeDays -gt 3) {
    "STALE"
} else {
    "ACTIVE"
}

Write-Host ""
switch ($currentState) {