Skip to content

Commit 3090c43

Browse files
committed
Use Version.Details.xml as VMR snapshot fallback for manual backflow
When someone runs 'darc vmr backflow' manually and pushes directly, the commit message doesn't contain the standard 'Backflow from ... / <sha>' format that the script parses. However, the VMR source SHA is always updated in eng/Version.Details.xml's <Source> element. This adds a fallback: when no VMR SHA is found in commit messages, read Version.Details.xml from the PR branch to get the actual snapshot. This gives accurate freshness reporting and fix tracing even after manual backflow operations.
1 parent a9ea742 commit 3090c43

File tree

1 file changed

+40
-15
lines changed

1 file changed

+40
-15
lines changed

.github/skills/vmr-codeflow-status/scripts/Get-CodeflowStatus.ps1

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -420,19 +420,34 @@ if ($prCommits) {
420420
}
421421
}
422422

423+
# Fallback: if no VMR SHA found in commit messages, check eng/Version.Details.xml on the PR branch
424+
# This catches manual backflow (e.g., `darc vmr backflow` pushed directly) which updates
425+
# the <Source> element but doesn't use a parseable commit message format
426+
$versionDetailsVmrCommit = $null
427+
if (-not $branchVmrCommit -and -not $isForwardFlow) {
428+
$vdContent = Invoke-GitHubApi "/repos/$Repository/contents/eng/Version.Details.xml?ref=$([System.Uri]::EscapeDataString($pr.headRefName))" -Raw
429+
if ($vdContent -and $vdContent -match '<Source\s+[^>]*Sha="([a-fA-F0-9]+)"') {
430+
$versionDetailsVmrCommit = $Matches[1]
431+
if (-not $vmrCommit -or -not ($vmrCommit.StartsWith($versionDetailsVmrCommit) -or $versionDetailsVmrCommit.StartsWith($vmrCommit))) {
432+
$branchVmrCommit = $versionDetailsVmrCommit
433+
}
434+
}
435+
}
436+
423437
if ($branchVmrCommit -or $vmrCommit) {
424438
Write-Section "Snapshot Validation"
425439
$usedBranchSnapshot = $false
426440
if ($branchVmrCommit -and $vmrCommit) {
427441
$bodyShort = Get-ShortSha $vmrCommit
428-
$branchShort = $branchVmrCommit # already short from commit message
442+
$branchShort = Get-ShortSha $branchVmrCommit
443+
$snapshotSourceLabel = if ($versionDetailsVmrCommit -and $branchVmrCommit -eq $versionDetailsVmrCommit) { "Version.Details.xml" } else { "branch commit" }
429444
if ($vmrCommit.StartsWith($branchVmrCommit) -or $branchVmrCommit.StartsWith($vmrCommit)) {
430-
Write-Host " ✅ PR body snapshot ($bodyShort) matches branch commit ($branchShort)" -ForegroundColor Green
445+
Write-Host " ✅ PR body snapshot ($bodyShort) matches $snapshotSourceLabel ($branchShort)" -ForegroundColor Green
431446
}
432447
else {
433-
Write-Host " ⚠️ MISMATCH: PR body claims $(Get-ShortSha $vmrCommit) but branch commit references $branchVmrCommit" -ForegroundColor Red
434-
Write-Host " The PR body may be stale — using branch commit ($branchVmrCommit) for freshness check" -ForegroundColor Yellow
435-
# Resolve the short SHA from the branch commit to a full SHA for accurate comparison
448+
Write-Host " ⚠️ MISMATCH: PR body claims $bodyShort but $snapshotSourceLabel references $branchShort" -ForegroundColor Red
449+
Write-Host " The PR body may be stale — using $snapshotSourceLabel ($branchShort) for freshness check" -ForegroundColor Yellow
450+
# Resolve the SHA to a full SHA for accurate comparison
436451
$resolvedCommit = Invoke-GitHubApi "/repos/$freshnessRepo/commits/$branchVmrCommit"
437452
if ($resolvedCommit) {
438453
$vmrCommit = $resolvedCommit.sha
@@ -453,19 +468,26 @@ if ($branchVmrCommit -or $vmrCommit) {
453468
}
454469
}
455470
elseif ($vmrCommit -and -not $branchVmrCommit) {
456-
$commitCount = if ($prCommits) { $prCommits.Count } else { 0 }
457-
if ($commitCount -eq 1) {
458-
$firstMsg = $prCommits[0].messageHeadline
459-
if ($firstMsg -match "^Initial commit for subscription") {
460-
Write-Host " ℹ️ PR has only an initial subscription commit — PR body snapshot ($(Get-ShortSha $vmrCommit)) not yet verifiable from branch" -ForegroundColor DarkGray
471+
# No mismatch from commit messages or Version.Details.xml
472+
# Check if Version.Details.xml confirmed the PR body SHA
473+
if ($versionDetailsVmrCommit -and ($vmrCommit.StartsWith($versionDetailsVmrCommit) -or $versionDetailsVmrCommit.StartsWith($vmrCommit))) {
474+
Write-Host " ✅ PR body snapshot ($(Get-ShortSha $vmrCommit)) confirmed by Version.Details.xml" -ForegroundColor Green
475+
}
476+
else {
477+
$commitCount = if ($prCommits) { $prCommits.Count } else { 0 }
478+
if ($commitCount -eq 1) {
479+
$firstMsg = $prCommits[0].messageHeadline
480+
if ($firstMsg -match "^Initial commit for subscription") {
481+
Write-Host " ℹ️ PR has only an initial subscription commit — PR body snapshot ($(Get-ShortSha $vmrCommit)) not yet verifiable from branch" -ForegroundColor DarkGray
482+
}
483+
else {
484+
Write-Host " ⚠️ No VMR SHA found in branch commit messages — trusting PR body ($(Get-ShortSha $vmrCommit))" -ForegroundColor Yellow
485+
}
461486
}
462487
else {
463-
Write-Host " ⚠️ No VMR SHA found in branch commit messages — trusting PR body ($(Get-ShortSha $vmrCommit))" -ForegroundColor Yellow
488+
Write-Host " ⚠️ No VMR SHA found in $commitCount branch commit messages — trusting PR body ($(Get-ShortSha $vmrCommit))" -ForegroundColor Yellow
464489
}
465490
}
466-
else {
467-
Write-Host " ⚠️ No VMR SHA found in $commitCount branch commit messages — trusting PR body ($(Get-ShortSha $vmrCommit))" -ForegroundColor Yellow
468-
}
469491
}
470492
}
471493

@@ -485,7 +507,10 @@ if ($vmrCommit -and $vmrBranch) {
485507
if ($branchHead) {
486508
$sourceHeadSha = $branchHead.sha
487509
$sourceHeadDate = $branchHead.commit.committer.date
488-
$snapshotSource = if ($usedBranchSnapshot) { "from branch commit" } else { "from PR body" }
510+
$snapshotSource = if ($usedBranchSnapshot) {
511+
if ($versionDetailsVmrCommit -and $vmrCommit.StartsWith($versionDetailsVmrCommit)) { "from Version.Details.xml" }
512+
else { "from branch commit" }
513+
} else { "from PR body" }
489514
Write-Status "PR snapshot" "$(Get-ShortSha $vmrCommit) ($snapshotSource)"
490515
Write-Status "$freshnessRepoLabel HEAD" "$(Get-ShortSha $sourceHeadSha) ($sourceHeadDate)"
491516

0 commit comments

Comments
 (0)