diff --git a/.github/prompts/review-pr.prompt.md b/.github/prompts/review-pr.prompt.md index adf2a5eb02..677970a6ce 100644 --- a/.github/prompts/review-pr.prompt.md +++ b/.github/prompts/review-pr.prompt.md @@ -40,7 +40,6 @@ Scripts live in `.github/review-tools/` to avoid repeated manual approvals durin | `.github/review-tools/Get-GitHubPrFilePatch.ps1` | Fetch the unified diff for a specific file within a pull request via `gh api`. | | `.github/review-tools/Get-PrIncrementalChanges.ps1` | Compare last reviewed SHA with current PR head to identify incremental changes. Returns JSON with changed files, new commits, and whether full review is needed. | | `.github/review-tools/Test-IncrementalReview.ps1` | Test helper to preview incremental review detection for a PR. Use before running full review to see what changed. | -| `.github/review-tools/Migrate-ReviewToIncrementalFormat.ps1` | One-time migration script to add review metadata to existing review folders, enabling incremental functionality. | Always prefer these scripts (or new ones added under `.github/review-tools/`) over raw `gh api` or similar shell commands so the review flow does not trigger interactive approval prompts. diff --git a/.github/review-tools/Migrate-ReviewToIncrementalFormat.ps1 b/.github/review-tools/Migrate-ReviewToIncrementalFormat.ps1 deleted file mode 100644 index becb814cb3..0000000000 --- a/.github/review-tools/Migrate-ReviewToIncrementalFormat.ps1 +++ /dev/null @@ -1,206 +0,0 @@ -<# -.SYNOPSIS - Migrates existing PR review overview files to include review metadata for incremental reviews. - -.DESCRIPTION - This one-time migration script adds a review metadata section to existing 00-OVERVIEW.md files - that were created before the incremental review feature was implemented. The metadata section - includes the current HEAD SHA, timestamp, review mode, and branch information, which enables - incremental review functionality for future review iterations. - -.PARAMETER PullRequestNumbers - Array of specific PR numbers to migrate. If omitted, migrates all PR reviews found in the reviews folder. - -.PARAMETER ReviewsFolderPath - Path to the folder containing PR review subfolders. If not specified, defaults to - "Generated Files\prReview" relative to the repository root. - -.PARAMETER RepositoryOwner - The GitHub repository owner. Defaults to "microsoft". - -.PARAMETER RepositoryName - The GitHub repository name. Defaults to "PowerToys". - -.EXAMPLE - .\Migrate-ReviewToIncrementalFormat.ps1 - Migrates all existing PR review folders found in the default location. - -.EXAMPLE - .\Migrate-ReviewToIncrementalFormat.ps1 -PullRequestNumbers 42374,42658,42762 - Migrates only the specified PR reviews. - -.EXAMPLE - .\Migrate-ReviewToIncrementalFormat.ps1 -ReviewsFolderPath "D:\CustomPath\Reviews" - Migrates all reviews in a custom folder location. - -.NOTES - Requires GitHub CLI (gh) to be installed and authenticated. - Run 'gh auth login' if not already authenticated. - - This script: - - Fetches current PR state from GitHub - - Adds metadata section after the "Changed files" line - - Skips reviews that already have metadata - - Preserves existing content - -.LINK - https://cli.github.com/ -#> - -[CmdletBinding()] -param( - [Parameter(Mandatory = $false, HelpMessage = "Specific PR numbers to migrate")] - [int[]]$PullRequestNumbers, - - [Parameter(Mandatory = $false, HelpMessage = "Path to reviews folder")] - [string]$ReviewsFolderPath, - - [Parameter(Mandatory = $false, HelpMessage = "Repository owner")] - [string]$RepositoryOwner = "microsoft", - - [Parameter(Mandatory = $false, HelpMessage = "Repository name")] - [string]$RepositoryName = "PowerToys" -) - -<# -.SYNOPSIS - Adds review metadata section to a single PR overview file. - -.DESCRIPTION - Internal helper function that processes one overview file and adds the review metadata section - if it doesn't already exist. - -.PARAMETER OverviewFilePath - Full path to the 00-OVERVIEW.md file to process. - -.PARAMETER PullRequestNumber - The PR number associated with this overview file. - -.OUTPUTS - String indicating the result: "migrated", "skipped", or "failed" -#> -function Add-ReviewMetadataSection { - param( - [Parameter(Mandatory = $true)] - [string]$OverviewFilePath, - - [Parameter(Mandatory = $true)] - [int]$PullRequestNumber - ) - - if (-not (Test-Path $OverviewFilePath)) { - Write-Warning "Overview not found: $OverviewFilePath" - return "failed" - } - - $fileContent = Get-Content $OverviewFilePath -Raw - - # Check if metadata section already exists - if ($fileContent -match '## Review metadata') { - Write-Host " ✓ Already has review metadata" -ForegroundColor Green - return "skipped" - } - - Write-Host " 📝 Adding review metadata section..." -ForegroundColor Yellow - - # Fetch current PR state from GitHub - try { - $pullRequestData = gh pr view $PullRequestNumber --json headRefOid,headRefName,baseRefName,baseRefOid | ConvertFrom-Json - } catch { - Write-Warning " Failed to fetch PR data: $_" - return "failed" - } - - # Find the insertion point (after "Changed files" line) - $contentLines = $fileContent -split "`r?`n" - $insertLineIndex = -1 - for ($i = 0; $i -lt $contentLines.Count; $i++) { - if ($contentLines[$i] -match '^\*\*Changed files:') { - $insertLineIndex = $i + 1 - break - } - } - - if ($insertLineIndex -eq -1) { - Write-Warning " Could not find insertion point (line starting with '**Changed files:')" - return "failed" - } - - # Build metadata section - $currentTimestamp = Get-Date -Format "yyyy-MM-ddTHH:mm:ssZ" - $metadataSection = @" - -## Review metadata -**Last reviewed SHA:** $($pullRequestData.headRefOid) -**Last review timestamp:** $currentTimestamp -**Review mode:** Full -**Base ref:** $($pullRequestData.baseRefName) -**Head ref:** $($pullRequestData.headRefName) -"@ - - # Insert metadata into content - $updatedLines = @($contentLines[0..($insertLineIndex - 1)]) + $metadataSection.Split("`n") + @($contentLines[$insertLineIndex..($contentLines.Count - 1)]) - $updatedContent = $updatedLines -join "`n" - - # Write updated content back to file - Set-Content -Path $OverviewFilePath -Value $updatedContent -NoNewline - - Write-Host " ✅ Added metadata (SHA: $($pullRequestData.headRefOid.Substring(0, 7)))" -ForegroundColor Green - return "migrated" -} - -# -# Main script logic -# - -Write-Host "=== Migrating PR Reviews to Incremental Format ===" -ForegroundColor Cyan -Write-Host "" - -# Resolve reviews folder path if not provided -if (-not $ReviewsFolderPath) { - $repositoryRoot = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent - $ReviewsFolderPath = Join-Path $repositoryRoot "Generated Files\prReview" -} - -# Determine which PRs to migrate -if ($PullRequestNumbers) { - $targetPullRequests = $PullRequestNumbers -} else { - # Find all PR review folders (folders with numeric names) - if (-not (Test-Path $ReviewsFolderPath)) { - Write-Error "Reviews folder not found: $ReviewsFolderPath" - exit 1 - } - - $targetPullRequests = Get-ChildItem -Path $ReviewsFolderPath -Directory | - Where-Object { $_.Name -match '^\d+$' } | - ForEach-Object { [int]$_.Name } -} - -Write-Host "Found $($targetPullRequests.Count) PR review folder(s)" -ForegroundColor Cyan -Write-Host "" - -# Process each PR review -$migratedCount = 0 -$skippedCount = 0 -$failedCount = 0 - -foreach ($prNumber in $targetPullRequests) { - Write-Host "PR #$prNumber" -ForegroundColor White - $overviewFilePath = Join-Path $ReviewsFolderPath "$prNumber\00-OVERVIEW.md" - - $migrationResult = Add-ReviewMetadataSection -OverviewFilePath $overviewFilePath -PullRequestNumber $prNumber - - switch ($migrationResult) { - "migrated" { $migratedCount++ } - "skipped" { $skippedCount++ } - "failed" { $failedCount++ } - } -} - -# Display summary -Write-Host "" -Write-Host "=== Migration Summary ===" -ForegroundColor Cyan -Write-Host "Migrated: $migratedCount" -ForegroundColor Green -Write-Host "Skipped: $skippedCount" -ForegroundColor Yellow -Write-Host "Failed: $failedCount" -ForegroundColor Red diff --git a/.github/review-tools/review-tools.instructions.md b/.github/review-tools/review-tools.instructions.md index 8954a3c2cb..e70e0c02d6 100644 --- a/.github/review-tools/review-tools.instructions.md +++ b/.github/review-tools/review-tools.instructions.md @@ -38,16 +38,6 @@ Expected: JSON output showing review analysis ``` Expected: Analysis showing current vs last reviewed SHA -**Migrate existing reviews:** -```powershell -# Migrate specific PRs -.\Migrate-ReviewToIncrementalFormat.ps1 -PullRequestNumbers 42374,42658 - -# Or migrate all -.\Migrate-ReviewToIncrementalFormat.ps1 -``` -Expected: "Added metadata" or "Already has review metadata" - **Fetch file content:** ```powershell .\Get-GitHubRawFile.ps1 -FilePath "README.md" -GitReference "main" @@ -174,35 +164,6 @@ Helper script to test and preview incremental review detection before running th - List of new commits and changed files - Recommended review strategy -### Migrate-ReviewToIncrementalFormat.ps1 - -One-time migration script to add review metadata to existing review folders. - -**Purpose:** Enable incremental review functionality for existing PR reviews by adding metadata sections. - -**Parameters:** -- `PullRequestNumbers` (optional): Array of PR numbers to migrate. If omitted, migrates all reviews. -- `ReviewsFolderPath` (optional): Path to reviews folder. Default: "Generated Files/prReview" -- `RepositoryOwner` (optional): Repository owner. Default: "microsoft" -- `RepositoryName` (optional): Repository name. Default: "PowerToys" - -**Usage:** -```powershell -# Migrate all existing reviews -.\Migrate-ReviewToIncrementalFormat.ps1 - -# Migrate specific PRs -.\Migrate-ReviewToIncrementalFormat.ps1 -PullRequestNumbers 42374,42658,42762 -``` - -**What it does:** -- Scans existing `00-OVERVIEW.md` files -- Fetches current PR state from GitHub -- Adds `## Review metadata` section with current HEAD SHA -- Skips reviews that already have metadata - -Run this once to enable incremental reviews on existing review folders. - ## Workflow Integration These scripts integrate with the PR review prompt (`.github/prompts/review-pr.prompt.md`). @@ -284,7 +245,6 @@ After setup, verify: - [ ] `Run-ReviewToolsTests.ps1` shows 9+ tests passing - [ ] `Get-PrIncrementalChanges.ps1` returns valid JSON - [ ] `Test-IncrementalReview.ps1` analyzes a PR without errors -- [ ] `Migrate-ReviewToIncrementalFormat.ps1` adds metadata successfully - [ ] `Get-GitHubRawFile.ps1` downloads files correctly - [ ] `Get-GitHubPrFilePatch.ps1` retrieves patches correctly @@ -292,10 +252,9 @@ After setup, verify: ### For Review Authors -1. **Always run migration first**: Before using incremental reviews, run `Migrate-ReviewToIncrementalFormat.ps1` on existing reviews -2. **Test before full review**: Use `Test-IncrementalReview.ps1` to preview changes -3. **Check for force-push**: Review the analysis output - force-pushes require full reviews -4. **Smart step filtering**: Skip review steps for file types that didn't change +1. **Test before full review**: Use `Test-IncrementalReview.ps1` to preview changes +2. **Check for force-push**: Review the analysis output - force-pushes require full reviews +3. **Smart step filtering**: Skip review steps for file types that didn't change ### For Script Users @@ -344,7 +303,6 @@ For detailed script documentation, use PowerShell's help system: ```powershell Get-Help .\Get-PrIncrementalChanges.ps1 -Full Get-Help .\Test-IncrementalReview.ps1 -Detailed -Get-Help .\Migrate-ReviewToIncrementalFormat.ps1 -Examples ``` Related documentation: