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

Code before:
    $fwdPRsJson = gh search prs --repo dotnet/dotnet --author "dotnet-maestro[bot]" --state open "Source code updates from dotnet/$repoShortName" --json number,title --limit 50 2>$null
    $fwdPRs = @()
    if ($LASTEXITCODE -eq 0 -and $fwdPRsJson) {
        try { $fwdPRs = ($fwdPRsJson -join "`n") | ConvertFrom-Json } catch { $fwdPRs = @() }
    }
    # Filter to exact repo match (avoid dotnet/sdk matching dotnet/sdk-container-builds)
    $fwdPRs = @($fwdPRs | Where-Object { $_.title -match "from dotnet/$([regex]::Escape($repoShortName))$" })

    $fwdHealthy = 0
    $fwdStale = 0
    $fwdConflict = 0

    if ($fwdPRs.Count -eq 0) {
        Write-Host "  No open forward flow PRs found" -ForegroundColor DarkGray
    }
    else {
        foreach ($fpr in $fwdPRs) {
            $fprBranch = if ($fpr.title -match '^\[([^\]]+)\]') { $Matches[1] } else { "unknown" }
            if ($Branch -and $fprBranch -ne $Branch) { continue }

            # Get PR details for staleness/conflict check
            $fprDetailJson = gh pr view $fpr.number -R dotnet/dotnet --json body,comments,updatedAt 2>&1
            if ($LASTEXITCODE -ne 0) {
                Write-Host "  PR #$($fpr.number) [$fprBranch]: ⚠️  Could not fetch details" -ForegroundColor Yellow
                continue
            }
            $fprDetail = ($fprDetailJson -join "`n") | ConvertFrom-Json

            # Check for staleness warnings and conflicts in comments
            $hasStaleness = $false
            $hasConflict = $false
            if ($fprDetail.comments) {
                foreach ($comment in $fprDetail.comments) {
                    if ($comment.author.login -match '^dotnet-maestro') {
                        if ($comment.body -match 'codeflow cannot continue|the source repository has received code changes') { $hasStaleness = $true }
                        if ($comment.body -match 'Conflict detected') { $hasConflict = $true }
                    }
                }
            }

            $status = "✅ Healthy"
            $color = "Green"
            if ($hasConflict) {
                $status = "🔴 Conflict"
                $color = "Red"
                $fwdConflict++
            }
            elseif ($hasStaleness) {
                $status = "⚠️  Stale"
                $color = "Yellow"
                $fwdStale++

Review comment (bug):
`gh pr view ... --json ... 2>&1` merges stderr into stdout, which can corrupt the JSON stream (e.g., auth warnings) and make the subsequent `ConvertFrom-Json` fail or terminate the script. Prefer redirecting stderr separately (e.g., `2>$null`) or capturing stderr and only parsing stdout when `$LASTEXITCODE -eq 0`.

Code after:

    # --- Forward flow: check PRs from this repo into the VMR ---
    $repoShortName = $Repository -replace '^dotnet/', ''
    Write-Host ""
    Write-Section "Forward flow PRs ($Repository → dotnet/dotnet)"

    $fwdPRsJson = gh search prs --repo dotnet/dotnet --author "dotnet-maestro[bot]" --state open "Source code updates from dotnet/$repoShortName" --json number,title --limit 10 2>$null
    $fwdPRs = @()
    if ($LASTEXITCODE -eq 0 -and $fwdPRsJson) {
        try { $fwdPRs = ($fwdPRsJson -join "`n") | ConvertFrom-Json } catch { $fwdPRs = @() }
    }
    # Filter to exact repo match (avoid dotnet/sdk matching dotnet/sdk-container-builds)
    $fwdPRs = @($fwdPRs | Where-Object { $_.title -match "from dotnet/$([regex]::Escape($repoShortName))$" })

    $fwdHealthy = 0
    $fwdStale = 0
    $fwdConflict = 0

    if ($fwdPRs.Count -eq 0) {
        Write-Host "  No open forward flow PRs found" -ForegroundColor DarkGray
    }
    else {
        foreach ($fpr in $fwdPRs) {
            $fprBranch = if ($fpr.title -match '^\[([^\]]+)\]') { $Matches[1] } else { "unknown" }
            if ($Branch -and $fprBranch -ne $Branch) { continue }

            # Get PR details for staleness/conflict check
            $fprDetailJson = gh pr view $fpr.number -R dotnet/dotnet --json body,comments,updatedAt 2>$null
            if ($LASTEXITCODE -ne 0) {
                Write-Host "  PR #$($fpr.number) [$fprBranch]: ⚠️  Could not fetch details" -ForegroundColor Yellow
                continue
            }
            try {
                $fprDetail = ($fprDetailJson -join "`n") | ConvertFrom-Json
            }
            catch {
                Write-Host "  PR #$($fpr.number) [$fprBranch]: ⚠️  Could not parse details" -ForegroundColor Yellow
                continue
            }

            # Check for staleness warnings and conflicts in comments
            $hasStaleness = $false
            $hasConflict = $false
            if ($fprDetail.comments) {
                foreach ($comment in $fprDetail.comments) {
                    if ($comment.author.login -match '^dotnet-maestro') {
                        if ($comment.body -match 'codeflow cannot continue|the source repository has received code changes') { $hasStaleness = $true }
                        if ($comment.body -match 'Conflict detected') { $hasConflict = $true }
                    }
                }
            }