Skip to content

Commit

Permalink
Update YamlCreate to replace in-place for the Pull request template
Browse files Browse the repository at this point in the history
  • Loading branch information
Trenly committed Mar 15, 2024
1 parent 81da8d0 commit ea91dc3
Showing 1 changed file with 89 additions and 89 deletions.
178 changes: 89 additions & 89 deletions Tools/YamlCreate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <path>'?"
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 <path>'?"
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 <path>'?"
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 <path>'?"
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
Expand All @@ -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())) {
Expand All @@ -2207,15 +2208,15 @@ 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
if ($_responseCode -ne 200) {
Write-Host -ForegroundColor 'Red' "Invalid Issue: $i"
continue
}
$PrBodyContentReply += @("* Resolves #$i")
$PrBodyContent += @("* Resolves #$i")
}
}
}
Expand All @@ -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
}
Expand Down

1 comment on commit ea91dc3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log for details.

Unrecognized words (7)

aslo
hashses
imporant
lexographical
lexographically
Repology
seond

Previously acknowledged words that are now absent admins craigloewen Daa Esco fabricbot Filezilla jedieaston Joakim Kad Karan Levvie mdanish Megamix msft quhxl redistribution russellbanks Tbot timezone Trenly :arrow_right:
To accept ✔️ these unrecognized words as correct and remove the previously acknowledged and now absent words, run the following commands

... in a clone of the [email protected]:denelon/winget-pkgs.git repository
on the Documentation branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.21/apply.pl' |
perl - 'https://github.com/denelon/winget-pkgs/actions/runs/8302694230/attempts/1'
If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.