mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-23 19:49:43 +01:00
## Summary of the Pull Request This PR adds comprehensive GitHub PR review tooling infrastructure to improve review efficiency through incremental review capabilities. The tooling consists of PowerShell scripts that detect changes between review iterations, enabling reviewers to focus only on modified files, and AI prompt templates for structured PR and issue reviews. **Key additions:** - `.github/review-tools/`: PowerShell scripts for incremental PR review detection - `.github/prompts/`: AI prompt templates for PR reviews, issue reviews, and issue fixes - Copilot instructions documentation for review tools integration ## PR Checklist - [ ] Closes: #xxx - [x] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass (N/A - tooling scripts with manual validation) - [x] **Localization:** All end-user-facing strings can be localized (N/A - development tooling only) - [x] **Dev docs:** Added/updated (comprehensive documentation in `review-tools.instructions.md`) - [ N/A ] **New binaries:** Added on the required places (N/A - PowerShell scripts, no binaries) - [ N/A ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx (N/A - internal development tooling) ## Detailed Description of the Pull Request / Additional comments ### Review Tools Added (`.github/review-tools/`) **Core Scripts:** 1. **`Get-PrIncrementalChanges.ps1`** (173 lines) - Compares last reviewed commit SHA with current PR head to identify incremental changes. Returns JSON with changed files, new commits, and review recommendations. Handles scenarios: first review, no changes, force-push detection, and incremental changes. 2. **`Test-IncrementalReview.ps1`** (170 lines) - Helper script to preview incremental review detection before running full review. Displays colored console output showing current vs last reviewed SHAs, changed files, new commits, and recommended review strategy. 3. **`Migrate-ReviewToIncrementalFormat.ps1`** (206 lines) - One-time migration script to add review metadata sections to existing `00-OVERVIEW.md` files, enabling incremental review functionality for legacy PR reviews. 4. **`Get-GitHubRawFile.ps1`** (91 lines) - Downloads file content from GitHub repository at specific git reference for baseline comparison during reviews. Supports optional line numbering. 5. **`Get-GitHubPrFilePatch.ps1`** (79 lines) - Fetches unified diff (patch) for a specific file in a pull request using GitHub API. 6. **`review-tools.instructions.md`** (355 lines) - Comprehensive documentation covering script usage, workflow integration, error handling, best practices, and AI integration examples. Serves as Copilot instructions for the review tools. ### AI Prompt Templates Added (`.github/prompts/`) 1. **`review-pr.prompt.md`** (200 lines) - Structured prompt for comprehensive PR reviews with incremental review support 2. **`review-issue.prompt.md`** (158 lines) - Template for systematic issue analysis and triage 3. **`fix-issue.prompt.md`** (71 lines) - Guided workflow for implementing issue fixes 4. **Minor updates** to `create-commit-title.prompt.md` and `create-pr-summary.prompt.md` for consistency ### Key Features **Incremental Review Flow:** - Initial review (iteration 1): Creates overview with metadata including HEAD SHA - Subsequent reviews (iteration 2+): Reads last reviewed SHA, detects changes, reviews only modified files - Smart step filtering: Skips irrelevant review steps based on file types changed (e.g., skip Localization if no `.resx` files changed) **Error Handling:** - Detects force-push scenarios (last reviewed SHA no longer in history) - Validates GitHub CLI authentication - Provides detailed error messages with actionable solutions - Exit code 1 on errors for automation compatibility **Integration:** - Works with GitHub CLI (`gh`) for API access - JSON output for programmatic consumption - Designed for AI-powered review systems (Copilot integration) - Metadata tracking for context-aware suggestions ## Validation Steps Performed **Manual Testing:** 1. ✅ Verified all PowerShell scripts follow PSScriptAnalyzer rules 2. ✅ Tested `Get-PrIncrementalChanges.ps1` with various scenarios: - First review (no previous SHA) - No changes (SHA matches current) - Force-push detection (SHA not in history) - Incremental changes (multiple commits and files) 3. ✅ Validated `Test-IncrementalReview.ps1` output formatting and accuracy 4. ✅ Confirmed `Migrate-ReviewToIncrementalFormat.ps1` adds metadata without corrupting existing reviews 5. ✅ Tested GitHub API integration with `Get-GitHubRawFile.ps1` and `Get-GitHubPrFilePatch.ps1` 6. ✅ Verified documentation accuracy and completeness in `review-tools.instructions.md` 7. ✅ Validated prompt templates follow PowerToys repo conventions from `.github/copilot-instructions.md` **Dependencies Verified:** - Requires PowerShell 7+ (or Windows PowerShell 5.1+) - Requires GitHub CLI (`gh`) installed and authenticated - All scripts include comprehensive help documentation (`Get-Help` support) **No Automated Tests:** These are development/CI tooling scripts used by maintainers for PR reviews. Manual validation appropriate as they interact with live GitHub API and require human judgment for review quality assessment.
92 lines
3.2 KiB
PowerShell
92 lines
3.2 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Downloads and displays the content of a file from a GitHub repository at a specific git reference.
|
|
|
|
.DESCRIPTION
|
|
This script fetches the raw content of a file from a GitHub repository using GitHub's raw content API.
|
|
It can optionally display line numbers and supports any valid git reference (branch, tag, or commit SHA).
|
|
|
|
.PARAMETER FilePath
|
|
The relative path to the file in the repository (e.g., "src/modules/main.cpp").
|
|
|
|
.PARAMETER GitReference
|
|
The git reference (branch name, tag, or commit SHA) to fetch the file from. Defaults to "main".
|
|
|
|
.PARAMETER RepositoryOwner
|
|
The GitHub repository owner. Defaults to "microsoft".
|
|
|
|
.PARAMETER RepositoryName
|
|
The GitHub repository name. Defaults to "PowerToys".
|
|
|
|
.PARAMETER ShowLineNumbers
|
|
When specified, displays line numbers before each line of content.
|
|
|
|
.PARAMETER StartLineNumber
|
|
The starting line number to use when ShowLineNumbers is enabled. Defaults to 1.
|
|
|
|
.EXAMPLE
|
|
.\Get-GitHubRawFile.ps1 -FilePath "README.md" -GitReference "main"
|
|
Downloads and displays the README.md file from the main branch.
|
|
|
|
.EXAMPLE
|
|
.\Get-GitHubRawFile.ps1 -FilePath "src/runner/main.cpp" -GitReference "dev/feature-branch" -ShowLineNumbers
|
|
Downloads main.cpp from a feature branch and displays it with line numbers.
|
|
|
|
.EXAMPLE
|
|
.\Get-GitHubRawFile.ps1 -FilePath "LICENSE" -GitReference "abc123def" -ShowLineNumbers -StartLineNumber 10
|
|
Downloads the LICENSE file from a specific commit and displays it with line numbers starting at 10.
|
|
|
|
.NOTES
|
|
Requires internet connectivity to access GitHub's raw content API.
|
|
Does not require GitHub CLI authentication for public repositories.
|
|
|
|
.LINK
|
|
https://docs.github.com/en/rest/repos/contents
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory = $true, HelpMessage = "Relative path to the file in the repository")]
|
|
[string]$FilePath,
|
|
|
|
[Parameter(Mandatory = $false, HelpMessage = "Git reference (branch, tag, or commit SHA)")]
|
|
[string]$GitReference = "main",
|
|
|
|
[Parameter(Mandatory = $false, HelpMessage = "Repository owner")]
|
|
[string]$RepositoryOwner = "microsoft",
|
|
|
|
[Parameter(Mandatory = $false, HelpMessage = "Repository name")]
|
|
[string]$RepositoryName = "PowerToys",
|
|
|
|
[Parameter(Mandatory = $false, HelpMessage = "Display line numbers before each line")]
|
|
[switch]$ShowLineNumbers,
|
|
|
|
[Parameter(Mandatory = $false, HelpMessage = "Starting line number for display")]
|
|
[int]$StartLineNumber = 1
|
|
)
|
|
|
|
# Construct the raw content URL
|
|
$rawContentUrl = "https://raw.githubusercontent.com/$RepositoryOwner/$RepositoryName/$GitReference/$FilePath"
|
|
|
|
# Fetch the file content from GitHub
|
|
try {
|
|
$response = Invoke-WebRequest -UseBasicParsing -Uri $rawContentUrl
|
|
} catch {
|
|
Write-Error "Failed to fetch file from $rawContentUrl. Details: $_"
|
|
exit 1
|
|
}
|
|
|
|
# Split content into individual lines
|
|
$contentLines = $response.Content -split "`n"
|
|
|
|
# Display the content with or without line numbers
|
|
if ($ShowLineNumbers) {
|
|
$currentLineNumber = $StartLineNumber
|
|
foreach ($line in $contentLines) {
|
|
Write-Output ("{0:d4}: {1}" -f $currentLineNumber, $line)
|
|
$currentLineNumber++
|
|
}
|
|
} else {
|
|
$contentLines | ForEach-Object { Write-Output $_ }
|
|
}
|