1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- # This script does a checkout of a Pull Request using the GitHub CLI, and then runs it using SandboxTest.ps1.
- Param(
- [Parameter(Position = 0, HelpMessage = "The Pull Request to checkout.", Mandatory=$true)]
- [String] $PullRequest,
- [Parameter(HelpMessage = "Open the Pull Request's review page in the default browser")]
- [Switch] $Review = $false,
- [Switch] $KeepBranch = $false,
- [Switch] $Prerelease = $false,
- [Switch] $EnableExperimentalFeatures = $false
- )
- $PullRequest = $PullRequest.TrimStart('#')
- $ErrorActionPreference = "Stop"
- $repositoryRoot = "https://github.com/microsoft/winget-pkgs/"
- $rootDirectory = ((Resolve-Path (git rev-parse --show-toplevel)).ToString() + "\")
- if (-Not (Get-Command "gh" -ErrorAction "SilentlyContinue")) {
- Write-Host "The GitHub CLI is not installed. Install it via 'winget install gh' and come back here!" -ForegroundColor Red
- return
- }
- if (-Not (Get-Command "git" -ErrorAction "SilentlyContinue")) {
- Write-Host "Git is not installed. Install it via 'winget install git' and come back here!" -ForegroundColor Red
- return
- }
- gh pr checkout $PullRequest $(if (!$KeepBranch){'--detach'}) -f | Out-Null
- if($LASTEXITCODE -ne 0) {
- Write-Host "There was an error checking out the PR. Make sure you're logged into GitHub via 'gh auth login' and come back here!" -ForegroundColor Red
- return
- }
- $manifest = (git diff --name-only HEAD~1..HEAD)
- if ($manifest.GetType().Name -eq "Object[]") {
- $path = (Get-Item (Resolve-Path ($rootDirectory + $manifest[0]))).Directory
- }
- else {
- $path = (Get-Item (Resolve-Path ($rootDirectory + $manifest))).Directory
- }
- $sandboxTestPath = (Resolve-Path ($PSScriptRoot.ToString() + "\SandboxTest.ps1")).ToString()
- $params = @{
- Manifest = $path
- SkipManifestValidation = $true
- Prerelease = $Prerelease
- EnableExperimentalFeatures = $EnableExperimentalFeatures
- }
- & $sandboxTestPath @params
- if ($Review) {
- Write-Host "Opening $PullRequest in browser..." -ForegroundColor Green
- Start-Process ($repositoryRoot + "pull/" + $PullRequest + "/files")
- }
|