diff --git a/Tools/YamlCreate.ps1 b/Tools/YamlCreate.ps1 index f387767a5f52f..6982d09fd9429 100644 --- a/Tools/YamlCreate.ps1 +++ b/Tools/YamlCreate.ps1 @@ -168,7 +168,7 @@ if ($Settings) { exit } -$ScriptHeader = '# Created with YamlCreate.ps1 v2.3.5' +$ScriptHeader = '# Created with YamlCreate.ps1 v2.4.0' $ManifestVersion = '1.6.0' $PSDefaultParameterValues = @{ '*:Encoding' = 'UTF8' } $Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False @@ -2059,114 +2059,114 @@ Function Read-LocaleMetadata { # Uses this template and responses to create a PR Function Read-PRBody { $PrBodyContent = Get-Content $args[0] - ForEach ($_line in ($PrBodyContent| Where-Object { $_ -like '-*[ ]*' })) { - $_showMenu = $true - switch -Wildcard ( $_line ) { - '*CLA*' { - if ($ScriptSettings.SignedCLA -eq 'true') { - $PrBodyContentReply += @($_line.Replace('[ ]', '[X]')) - $_showMenu = $false - } else { + ForEach ($_line in $PrBodyContent) { + # | Where-Object { $_ -like '-*[ ]*' })) + if ($_line -like '-*[ ]*' ) + { + $_showMenu = $true + switch -Wildcard ( $_line ) { + '*CLA*' { + if ($ScriptSettings.SignedCLA -eq 'true') { + $PrBodyContent = $PrBodyContent.Replace($_line,$_line.Replace('[ ]','[x]')) + $_showMenu = $false + } else { + $_menu = @{ + Prompt = 'Have you signed the Contributor License Agreement (CLA)?' + Entries = @('[Y] Yes'; '*[N] No') + HelpText = 'Reference Link: https://cla.opensource.microsoft.com/microsoft/winget-pkgs' + HelpTextColor = '' + DefaultString = 'N' + } + } + } + + '*open `[pull requests`]*' { $_menu = @{ - Prompt = 'Have you signed the Contributor License Agreement (CLA)?' + Prompt = "Have you checked that there aren't other open pull requests for the same manifest update/change?" Entries = @('[Y] Yes'; '*[N] No') - HelpText = 'Reference Link: https://cla.opensource.microsoft.com/microsoft/winget-pkgs' + HelpText = 'Reference Link: https://github.com/microsoft/winget-pkgs/pulls' HelpTextColor = '' DefaultString = 'N' } } - } - '*open `[pull requests`]*' { - $_menu = @{ - Prompt = "Have you checked that there aren't other open pull requests for the same manifest update/change?" - Entries = @('[Y] Yes'; '*[N] No') - HelpText = 'Reference Link: https://github.com/microsoft/winget-pkgs/pulls' - HelpTextColor = '' - DefaultString = 'N' + '*winget validate*' { + if ($? -and $(Get-Command 'winget' -ErrorAction SilentlyContinue)) { + $PrBodyContent = $PrBodyContent.Replace($_line,$_line.Replace('[ ]','[x]')) + $_showMenu = $false + } elseif ($script:Option -ne 'RemoveManifest') { + $_menu = @{ + Prompt = "Have you validated your manifest locally with 'winget validate --manifest '?" + Entries = @('[Y] Yes'; '*[N] No') + HelpText = 'Automatic manifest validation failed. Check your manifest and try again' + HelpTextColor = 'Red' + DefaultString = 'N' + } + } else { + $_showMenu = $false + } } - } - '*winget validate*' { - if ($? -and $(Get-Command 'winget' -ErrorAction SilentlyContinue)) { - $PrBodyContentReply += @($_line.Replace('[ ]', '[X]')) - $_showMenu = $false - } elseif ($script:Option -ne 'RemoveManifest') { - $_menu = @{ - Prompt = "Have you validated your manifest locally with 'winget validate --manifest '?" - Entries = @('[Y] Yes'; '*[N] No') - HelpText = 'Automatic manifest validation failed. Check your manifest and try again' - HelpTextColor = 'Red' - DefaultString = 'N' + '*tested your manifest*' { + if ($script:SandboxTest -eq '0') { + $PrBodyContent = $PrBodyContent.Replace($_line,$_line.Replace('[ ]','[x]')) + $_showMenu = $false + } elseif ($script:Option -ne 'RemoveManifest') { + $_menu = @{ + Prompt = "Have you tested your manifest locally with 'winget install --manifest '?" + Entries = @('[Y] Yes'; '*[N] No') + HelpText = 'You did not test your Manifest in Windows Sandbox previously.' + HelpTextColor = 'Red' + DefaultString = 'N' + } + } else { + $_showMenu = $false } - } else { - $_showMenu = $false - $PrBodyContentReply += @($_line) } - } - '*tested your manifest*' { - if ($script:SandboxTest -eq '0') { - $PrBodyContentReply += @($_line.Replace('[ ]', '[X]')) - $_showMenu = $false - } elseif ($script:Option -ne 'RemoveManifest') { - $_menu = @{ - Prompt = "Have you tested your manifest locally with 'winget install --manifest '?" - Entries = @('[Y] Yes'; '*[N] No') - HelpText = 'You did not test your Manifest in Windows Sandbox previously.' - HelpTextColor = 'Red' - DefaultString = 'N' + '*schema*' { + if ($script:Option -ne 'RemoveManifest') { + $_Match = ($_line | Select-String -Pattern 'https://+.+(?=\))').Matches.Value + $_menu = @{ + Prompt = $_line.TrimStart('- [ ]') -replace '\[|\]|\(.+\)', '' + Entries = @('[Y] Yes'; '*[N] No') + HelpText = "Reference Link: $_Match" + HelpTextColor = '' + DefaultString = 'N' + } + } else { + $_showMenu = $false } - } else { + } + + '*only modifies one*' { + $PrBodyContent = $PrBodyContent.Replace($_line,$_line.Replace('[ ]','[x]')) + $_showMenu = $false + } + + '*linked issue*' { + # Linked issues is handled as a separate prompt below so that the issue numbers can be gathered $_showMenu = $false - $PrBodyContentReply += @($_line) } - } - '*schema*' { - if ($script:Option -ne 'RemoveManifest') { - $_Match = ($_line | Select-String -Pattern 'https://+.+(?=\))').Matches.Value + Default { $_menu = @{ - Prompt = $_line.TrimStart('- [ ]') -replace '\[|\]|\(.+\)', '' + Prompt = $_line.TrimStart('- [ ]') Entries = @('[Y] Yes'; '*[N] No') - HelpText = "Reference Link: $_Match" + HelpText = '' HelpTextColor = '' DefaultString = 'N' } - } else { - $_showMenu = $false - $PrBodyContentReply += @($_line) } } - '*only modifies one*' { - $PrBodyContentReply += @($_line.Replace('[ ]', '[X]')) - $_showMenu = $false - } - - '*linked issue*' { - # Linked issues is handled as a separate prompt below so that the issue numbers can be gathered - $PrBodyContentReply += @($_line) - $_showMenu = $false - } - - Default { - $_menu = @{ - Prompt = $_line.TrimStart('- [ ]') - Entries = @('[Y] Yes'; '*[N] No') - HelpText = '' - HelpTextColor = '' - DefaultString = 'N' + if ($_showMenu) { + switch ( Invoke-KeypressMenu -Prompt $_menu['Prompt'] -Entries $_menu['Entries'] -DefaultString $_menu['DefaultString'] -HelpText $_menu['HelpText'] -HelpTextColor $_menu['HelpTextColor']) { + 'Y' { $PrBodyContent = $PrBodyContent.Replace($_line,$_line.Replace('[ ]','[x]')) } + default { } } } } - - if ($_showMenu) { - switch ( Invoke-KeypressMenu -Prompt $_menu['Prompt'] -Entries $_menu['Entries'] -DefaultString $_menu['DefaultString'] -HelpText $_menu['HelpText'] -HelpTextColor $_menu['HelpTextColor']) { - 'Y' { $PrBodyContentReply += @($_line.Replace('[ ]', '[X]')) } - default { $PrBodyContentReply += @($_line) } - } - } } # Request user to enter if there were any issues resolved by the PR @@ -2177,13 +2177,14 @@ Function Read-PRBody { } switch ( Invoke-KeypressMenu -Prompt $_menu['Prompt'] -Entries $_menu['Entries'] -DefaultString $_menu['DefaultString']) { 'Y' { - $PrBodyContentReply.Where({$_ -match 'linked issues'}).ForEach({$_.Replace('[ ]', '[X]')}) + $_line = ($PrBodyContent | Select-String 'linked issue').Line + if ($_line) { $PrBodyContent = $PrBodyContent.Replace($_line,$_line.Replace('[ ]','[x]')) } # If there were issues resolved by the PR, request user to enter them Write-Host Write-Host "Enter issue number. For example`: 21983, 43509" $ResolvedIssues = Read-Host -Prompt 'Resolved Issues' | UniqueItems - $PrBodyContentReply += @('') + $PrBodyContent += @('') # Validate each of the issues entered by checking the URL to ensure it returns a 200 status code Foreach ($i in ($ResolvedIssues.Split(',').Trim())) { @@ -2207,7 +2208,7 @@ Function Read-PRBody { Write-Host -ForegroundColor 'Red' "Invalid Issue: $i" continue } - $PrBodyContentReply += @("Resolves $i") + $PrBodyContent += @("Resolves $i") } else { $_checkedURL = "https://github.com/microsoft/winget-pkgs/issues/$i" $_responseCode = Test-Url $_checkedURL @@ -2215,7 +2216,7 @@ Function Read-PRBody { Write-Host -ForegroundColor 'Red' "Invalid Issue: $i" continue } - $PrBodyContentReply += @("* Resolves #$i") + $PrBodyContent += @("* Resolves #$i") } } } @@ -2224,12 +2225,11 @@ Function Read-PRBody { # If we are removing a manifest, we need to include the reason if ($CommitType -eq 'Remove') { - $PrBodyContentReply = @("## $($script:RemovalReason)"; '') + $PrBodyContentReply + $PrBodyContent = @("## $($script:RemovalReason)"; '') + $PrBodyContent } # Write the PR using a temporary file - Set-Content -Path PrBodyFile -Value $PrBodyContentReply | Out-Null - return + Set-Content -Path PrBodyFile -Value $PrBodyContent | Out-Null gh pr create --body-file PrBodyFile -f Remove-Item PrBodyFile }