diff --git a/.github/skills/ai-summary-comment/scripts/post-try-fix-comment.ps1 b/.github/skills/ai-summary-comment/scripts/post-try-fix-comment.ps1 index 43d8a2fdc5ab..f5bcf49540c5 100644 --- a/.github/skills/ai-summary-comment/scripts/post-try-fix-comment.ps1 +++ b/.github/skills/ai-summary-comment/scripts/post-try-fix-comment.ps1 @@ -261,7 +261,6 @@ $statusEmoji = switch ($Status) { } # Build the new attempt section - compact format -# Note: blank line after is required for proper markdown rendering $attemptSection = @"
$statusEmoji Fix $AttemptNumber @@ -270,7 +269,7 @@ $attemptSection = @" # Show brief approach description if (-not [string]::IsNullOrWhiteSpace($Approach)) { - $attemptSection += "$Approach`n`n" + $attemptSection += "`n$Approach`n`n" } # Only show diff if available @@ -326,7 +325,10 @@ try { } # Build the try-fix section content -$tryFixHeader = "### 🔧 Try-Fix Analysis`n`n" +# Count existing attempts to show in summary +$existingAttemptCount = 0 +$passCount = 0 +$failCount = 0 # Extract existing try-fix section to preserve previous attempts $existingTryFixContent = "" @@ -336,22 +338,64 @@ if ($existingBody -match "(?s)$startPattern(.*?)$endPattern") { $existingTryFixContent = $Matches[1].Trim() } +# Extract just the inner attempt details (strip outer wrapper and headers) +$innerAttempts = "" +if ($existingTryFixContent -match '(?s)
\s*🔧 Try-Fix Analysis.*?\s*(.*?)\s*
\s*$') { + # New format - extract content inside the outer details + $innerAttempts = $Matches[1].Trim() +} elseif ($existingTryFixContent -match '(?s)### 🔧.*?`n`n(.*)') { + # Old header format + $innerAttempts = $Matches[1].Trim() +} else { + # Just use as-is but strip any stray headers + $innerAttempts = $existingTryFixContent -replace "(?s)^### 🔧[^\n]*\n+", "" +} + +# Strip any leading horizontal rules,
tags, or whitespace before the first
+$innerAttempts = $innerAttempts -replace "(?s)^\s*---\s*\n+", "" +$innerAttempts = $innerAttempts -replace "(?s)^(
\s*)+", "" +$innerAttempts = $innerAttempts.TrimStart() + +# Count existing attempts (only count inner
that are Fix attempts) +$existingAttemptCount = ([regex]::Matches($innerAttempts, '
\s*[✅❌🔨⚪]')).Count +$passCount = ([regex]::Matches($innerAttempts, '
\s*✅')).Count +$failCount = ([regex]::Matches($innerAttempts, '
\s*❌')).Count + # Check if this attempt number already exists and replace it, or add new -# Match both old format (Attempt N:) and new format (Fix N) -$attemptPattern = "(?s)
\s*.*?(Attempt $AttemptNumber`:|Fix $AttemptNumber).*?
" -if ($existingTryFixContent -match $attemptPattern) { +$attemptPattern = "(?s)
\s*[✅❌🔨⚪]\s*Fix $AttemptNumber.*?
" +if ($innerAttempts -match $attemptPattern) { Write-Host "Replacing existing Fix $AttemptNumber..." -ForegroundColor Yellow - $tryFixContent = $existingTryFixContent -replace $attemptPattern, $attemptSection -} elseif (-not [string]::IsNullOrWhiteSpace($existingTryFixContent)) { + $tryFixInnerContent = $innerAttempts -replace $attemptPattern, $attemptSection +} elseif (-not [string]::IsNullOrWhiteSpace($innerAttempts)) { Write-Host "Adding new Fix $AttemptNumber..." -ForegroundColor Yellow - # Remove header if present to avoid duplication - $existingTryFixContent = $existingTryFixContent -replace "^### 🔧 (Try-Fix Analysis|Fix Attempts)\s*`n*", "" - $tryFixContent = $tryFixHeader + $existingTryFixContent.TrimEnd() + "`n`n" + $attemptSection + $tryFixInnerContent = $innerAttempts.TrimEnd() + "`n`n" + $attemptSection } else { Write-Host "Creating first fix..." -ForegroundColor Yellow - $tryFixContent = $tryFixHeader + $attemptSection + $tryFixInnerContent = $attemptSection } +# Recalculate attempt statistics from the final content to ensure consistency +$totalAttemptCount = ([regex]::Matches($tryFixInnerContent, '
\s*[✅❌🔨⚪]')).Count +$passCount = ([regex]::Matches($tryFixInnerContent, '
\s*✅')).Count +$failCount = ([regex]::Matches($tryFixInnerContent, '
\s*❌')).Count + +# Build summary line with counts +$summaryStatus = if ($passCount -gt 0) { "✅ $passCount passed" } else { "" } +if ($failCount -gt 0) { + if ($summaryStatus -ne "") { $summaryStatus += ", " } + $summaryStatus += "❌ $failCount failed" +} +if ($summaryStatus -eq "") { $summaryStatus = "$totalAttemptCount attempt(s)" } + +# Wrap everything in a single collapsible section +$tryFixContent = @" +
+🔧 Try-Fix Analysis: $summaryStatus
+$tryFixInnerContent + +
+"@ + # Build the section with markers $tryFixSection = @" $SECTION_START