-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 36 additions & 7 deletions
43
modules/WingetMaintainerModule/Public/Test-ExistingPRs.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,52 @@ | ||
<# | ||
.SYNOPSIS | ||
Checks for existing pull requests (PRs) for a specified package identifier and version in the 'microsoft/winget-pkgs' repository. | ||
.DESCRIPTION | ||
The `Test-ExistingPRs` function searches for existing open and merged pull requests in the 'microsoft/winget-pkgs' repository that match the specified package identifier and version. | ||
It uses the GitHub CLI (`gh`) to perform the search and returns `true` if any matching PRs are found, otherwise returns `false`. | ||
.PARAMETER Version | ||
The version of the package to check for existing PRs. This parameter is mandatory. | ||
.PARAMETER PackageIdentifier | ||
The identifier of the package to check for existing PRs. This parameter is optional and defaults to the value of the `PackageName` environment variable if not specified. | ||
.EXAMPLE | ||
Test-ExistingPRs -Version "1.0.0" -PackageIdentifier "example.package" | ||
Checks for existing PRs for the package 'example.package' with version '1.0.0'. | ||
.EXAMPLE | ||
Test-ExistingPRs -Version "1.0.0" | ||
Checks for existing PRs for the package specified in the `PackageName` environment variable with version '1.0.0'. | ||
.OUTPUTS | ||
System.Boolean | ||
Returns `true` if any matching PRs are found, otherwise returns `false`. | ||
.NOTES | ||
This function requires the GitHub CLI (`gh`) to be installed and authenticated. | ||
#> | ||
function Test-ExistingPRs { | ||
param( | ||
[Parameter(Mandatory = $true)] [string] $latestVersion, | ||
[Parameter(Mandatory = $false)] [string] $wingetPackage = ${Env:PackageName} | ||
[Parameter(Mandatory = $true)] [string] $Version, | ||
[Parameter(Mandatory = $false)] [string] $PackageIdentifier = ${Env:PackageName} | ||
) | ||
Write-Host "Checking for exisitng PRs for $wingetPackage $($Latest.Version)" | ||
$ExistingOpenPRs = gh pr list --search "$($wingetPackage) $($latestVersion) in:title draft:false" --state 'open' --json 'title,url' --repo 'microsoft/winget-pkgs' | ConvertFrom-Json | ||
$ExistingMergedPRs = gh pr list --search "$($wingetPackage) $($latestVersion) in:title draft:false" --state 'merged' --json 'title,url' --repo 'microsoft/winget-pkgs' | ConvertFrom-Json | ||
Write-Host "Checking for existing PRs for $PackageIdentifier $Version" | ||
$ExistingOpenPRs = gh pr list --search "$($PackageIdentifier) $($Version) in:title draft:false" --state 'open' --json 'title,url' --repo 'microsoft/winget-pkgs' | ConvertFrom-Json | ||
$ExistingMergedPRs = gh pr list --search "$($PackageIdentifier) $($Version) in:title draft:false" --state 'merged' --json 'title,url' --repo 'microsoft/winget-pkgs' | ConvertFrom-Json | ||
$ExistingPRs = @($ExistingOpenPRs) + @($ExistingMergedPRs) | ||
|
||
if ($ExistingPRs.Count -gt 0) { | ||
$ExistingPRs | ForEach-Object { | ||
Write-Host "Found existing PR: $($_.title)" | ||
Write-Host "-> $($_.url)" | ||
} | ||
exit 0 | ||
return $true | ||
} | ||
else { | ||
|
||
return $true | ||
return $false | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters