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

Code before:
}

# --- Step 2: Current State (independent assessment from primary signals) ---
Write-Section "Current State"

# Check for empty diff (0 changed files)
$isEmptyDiff = ($pr.changedFiles -eq 0 -and $pr.additions -eq 0 -and $pr.deletions -eq 0)
if ($isEmptyDiff) {
    Write-Host "  📭 Empty diff: 0 changed files, 0 additions, 0 deletions" -ForegroundColor Yellow
}

# Check PR timeline for force pushes
$forcePushEvents = @()
$owner, $repo = $Repository -split '/'
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)
    }
}
catch {
    Write-Verbose "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) {

Review comment (bug):
Force-push detection silently falls back to “no force pushes” when the `gh api .../timeline` call fails (stderr is redirected and there’s no else-path logging). That can misclassify `currentState` (e.g., STALE vs IN_PROGRESS) without telling the user that timeline data couldn’t be fetched. Consider emitting a `Write-Verbose`/`Write-Warning` when `$LASTEXITCODE -ne 0`, and/or capturing a boolean in the summary (e.g., `forcePushes.fetchSucceeded`) so recommendation logic can account for missing timeline data.

Code after:
}

# --- Step 2: Current State (independent assessment from primary signals) ---
Write-Section "Current State"

# Check for empty diff (0 changed files)
$isEmptyDiff = ($pr.changedFiles -eq 0 -and $pr.additions -eq 0 -and $pr.deletions -eq 0)
if ($isEmptyDiff) {
    Write-Host "  📭 Empty diff: 0 changed files, 0 additions, 0 deletions" -ForegroundColor Yellow
}

# Check PR timeline for force pushes
$forcePushEvents = @()
$owner, $repo = $Repository -split '/'
$forcePushFetchSucceeded = $false
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) {