@@ -628,4 +628,98 @@ function Update-PsVersionInCode
628
628
}
629
629
}
630
630
631
- Export-ModuleMember - Function Get-ChangeLog , Get-NewOfficalPackage , Update-PsVersionInCode
631
+
632
+ # #############################
633
+ # . SYNOPSIS
634
+ # Test if the GithubCli is in the path
635
+ # #############################
636
+ function Test-GitHubCli {
637
+ $gitHubCli = Get-Command - Name ' gh' - ErrorAction SilentlyContinue
638
+
639
+ if ($gitHubCli ) {
640
+ return $true
641
+ } else {
642
+ return $false
643
+ }
644
+ }
645
+
646
+ # #############################
647
+ # . SYNOPSIS
648
+ # Test if the GithubCli is the required version
649
+ # #############################
650
+ function Test-GitHubCliVersion {
651
+ param (
652
+ [Parameter (Mandatory )]
653
+ [System.Management.Automation.SemanticVersion ]
654
+ $RequiredVersion
655
+ )
656
+ [System.Management.Automation.SemanticVersion ] $version = gh -- version | ForEach-Object {
657
+ if ($_ -match ' (\d+\.\d+\.\d+) ' ) {
658
+ $matches [1 ]
659
+ }
660
+ }
661
+
662
+ if ($version -ge $RequiredVersion ) {
663
+ return $true
664
+ } else {
665
+ return $false
666
+ }
667
+ }
668
+
669
+ # #############################
670
+ # . SYNOPSIS
671
+ # Gets a report of Backport PRs
672
+ #
673
+ # . PARAMETER Triage state
674
+ # The triage states of the PR. Consider, Approved or Done
675
+ #
676
+ # . PARAMETER Version
677
+ # The version of PowerShell the backport is targeting. 7.0, 7.2, 7.3, etc
678
+ #
679
+ # . PARAMETER Web
680
+ # A switch to open all the PRs in the browser
681
+ #
682
+ # #############################
683
+ function Get-PRBackportReport {
684
+ param (
685
+ [ValidateSet (' Consider' , ' Approved' , ' Done' )]
686
+ [String ] $TriageState = ' Approved' ,
687
+ [ValidatePattern (' ^\d+\.\d+$' )]
688
+ [string ] $Version ,
689
+ [switch ] $Web
690
+ )
691
+
692
+ if (! (Test-GitHubCli )) {
693
+ throw " GitHub CLI is not installed. Please install it from https://cli.github.com/"
694
+ }
695
+
696
+ $requiredVersion = ' 2.17'
697
+ if (! (Test-GitHubCliVersion - RequiredVersion $requiredVersion )) {
698
+ throw " Please upgrade the GitHub CLI to version $requiredVersion . Please install it from https://cli.github.com/"
699
+ }
700
+
701
+ if (! (gh auth status 2>&1 | Select-String ' logged in' )){
702
+ throw " Please login to GitHub CLI using 'gh auth login'"
703
+ }
704
+
705
+ $prs = gh pr list -- state merged -- label " Backport-$Version .x-$TriageState " -- json title, number, mergeCommit, mergedAt |
706
+ ConvertFrom-Json |
707
+ ForEach-Object {
708
+ [PScustomObject ]@ {
709
+ CommitId = $_.mergeCommit.oid
710
+ Number = $_.number
711
+ Title = $_.title
712
+ MergedAt = $_.mergedAt
713
+ }
714
+ } | Sort-Object - Property MergedAt
715
+
716
+ if ($Web ) {
717
+ $prs | ForEach-Object {
718
+ gh pr view $_.Number -- web
719
+ }
720
+ } else {
721
+ $prs
722
+ }
723
+ }
724
+
725
+ Export-ModuleMember - Function Get-ChangeLog , Get-NewOfficalPackage , Update-PsVersionInCode , Get-PRBackportReport
0 commit comments