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

Code before:
            $bodyShort = Get-ShortSha $vmrCommit
            if ($vmrCommit.StartsWith($branchVmrCommit) -or $branchVmrCommit.StartsWith($vmrCommit)) {
                Write-Host "  ✅ $sourceLabel ($branchShort) matches PR body ($bodyShort)" -ForegroundColor Green
            }
            else {
                Write-Host "  ⚠️  MISMATCH: $sourceLabel has $branchShort but PR body claims $bodyShort" -ForegroundColor Red
                Write-Host "  PR body is stale — using $sourceLabel for freshness check" -ForegroundColor Yellow
            }
        }
        else {
            Write-Host "  ℹ️  PR body has no commit reference — using $sourceLabel ($branchShort)" -ForegroundColor Yellow
        }

        # Resolve to full SHA for accurate comparison (skip API call if already full-length)
        if ($branchVmrCommit.Length -ge 40) {
            $vmrCommit = $branchVmrCommit
            $usedBranchSnapshot = $true
        }
        else {
            $resolvedCommit = Invoke-GitHubApi "/repos/$freshnessRepo/commits/$branchVmrCommit"
            if ($resolvedCommit) {
                $vmrCommit = $resolvedCommit.sha
                $usedBranchSnapshot = $true
            }
            elseif (-not $vmrCommit) {
                Write-Host "  ⚠️  Could not resolve $sourceLabel SHA $branchShort" -ForegroundColor Yellow
            }
        }
    }
    else {
        # No branch-derived snapshot — PR body only
        $commitCount = if ($prCommits) { $prCommits.Count } else { 0 }
        if ($commitCount -eq 1 -and $prCommits[0].messageHeadline -match "^Initial commit for subscription") {
            Write-Host "  ℹ️  PR has only an initial subscription commit — PR body snapshot ($(Get-ShortSha $vmrCommit)) not yet verifiable" -ForegroundColor DarkGray
        }
        else {
            Write-Host "  ⚠️  Could not verify PR body snapshot ($(Get-ShortSha $vmrCommit)) from branch" -ForegroundColor Yellow
        }
    }
}

# --- Step 3: Check source freshness ---
$freshnessLabel = if ($isForwardFlow) { "Source Freshness" } else { "VMR Freshness" }
Write-Section $freshnessLabel

$sourceHeadSha = $null
$aheadBy = 0
$behindBy = 0
$compareStatus = $null

if ($vmrCommit -and $vmrBranch) {

Review comment (bug):
In the mismatch case, the script prints that it will use the branch-derived snapshot for freshness checking, but if resolving the short SHA fails and `$vmrCommit` is already set from the PR body, it silently continues using the PR body without updating messaging. This can produce misleading output (claiming the PR body is stale/ignored when it wasn’t). Consider adjusting the messaging to only state it’s using the branch snapshot after successful resolution, or add an explicit fallback message when resolution fails and the script continues with the PR body.
```suggestion
            else {
                if ($vmrCommit) {
                    Write-Host "  ⚠️  Could not resolve $sourceLabel SHA $branchShort — falling back to PR body snapshot ($(Get-ShortSha $vmrCommit))" -ForegroundColor Yellow
                }
                else {
                    Write-Host "  ⚠️  Could not resolve $sourceLabel SHA $branchShort" -ForegroundColor Yellow
                }
```

Code after:
}

# Extract commit diff
if ($body -match '\*\*Commit Diff\*\*:\s*\[([^\]]+)\]\(([^\)]+)\)') {
    Write-Status "Commit Diff" $Matches[1]
}

# Extract associated repo changes from footer
$repoChanges = @()
$changeMatches = [regex]::Matches($body, '- (https://github\.com/([^/]+/[^/]+)/compare/([a-fA-F0-9]+)\.\.\.([a-fA-F0-9]+))')
foreach ($m in $changeMatches) {
    $repoChanges += @{
        URL      = $m.Groups[1].Value
        Repo     = $m.Groups[2].Value
        FromSha  = $m.Groups[3].Value
        ToSha    = $m.Groups[4].Value
    }
}
if ($repoChanges.Count -gt 0) {
    Write-Status "Associated Repos" "$($repoChanges.Count) repos with source changes"
}

if (-not $vmrCommit -or -not $vmrBranch) {
    Write-Warning "Could not parse VMR metadata from PR body. This may not be a codeflow PR."
    if (-not $vmrBranch) {
        # For backflow: infer from PR target (which is the product repo branch = VMR branch name)
        # For forward flow: infer from PR head branch pattern or source repo context
        if ($isForwardFlow) {
            $vmrBranch = $pr.headRefName -replace '^darc-', '' -replace '-[a-f0-9-]+$', ''
            if (-not $vmrBranch) { $vmrBranch = $pr.baseRefName }
        }
        else {
            $vmrBranch = $pr.baseRefName
        }
        Write-Status "Inferred Branch" "$vmrBranch (from PR metadata)"
    }
}

# For backflow: compare against VMR (dotnet/dotnet) branch HEAD
# For forward flow: compare against product repo branch HEAD
$freshnessRepo = if ($isForwardFlow) { $sourceRepo } else { "dotnet/dotnet" }
$freshnessRepoLabel = if ($isForwardFlow) { $sourceRepo } else { "VMR" }

# Pre-load PR commits for use in validation and later analysis
$prCommits = $pr.commits

# --- Step 2b: Determine actual VMR snapshot on the PR branch ---
# Priority: 1) Version.Details.xml (ground truth), 2) commit messages, 3) PR body
$branchVmrCommit = $null
$commitMsgVmrCommit = $null
$versionDetailsVmrCommit = $null