Repository: microsoft/terminal
File: tools/ReleaseEngineering/ServicingPipeline.ps1 (PowerShell)

Code before:

Function Done() {
    $Host.ExitNestedPrompt()
}

Function Abort() {
    $Global:Abort = $True
    $Host.ExitNestedPrompt()
}

Function Skip() {
    $Global:Skip = $True
    $Host.ExitNestedPrompt()
}

Function Reject() {
    $Global:Skip = $True
    $Global:Reject = $True
    $Host.ExitNestedPrompt()
}

$Script:TodoColumnName = "To Cherry Pick"
$Script:DoneColumnName = "Cherry Picked"
$Script:RejectColumnName = "Rejected"

# Propagate default values into all PSGitHub cmdlets
$PSDefaultParameterValues['*GitHub*:Owner'] = "microsoft"
$PSDefaultParameterValues['*GitHub*:RepositoryName'] = "terminal"

$Project = Get-GithubProject -Name "$Version Servicing Pipeline"
$AllColumns = Get-GithubProjectColumn -ProjectId $Project.id
$ToPickColumn = $AllColumns | ? Name -Eq $script:TodoColumnName
$DoneColumn = $AllColumns | ? Name -Eq $script:DoneColumnName
$RejectColumn = $AllColumns | ? Name -Eq $script:RejectColumnName
$Cards = Get-GithubProjectCard -ColumnId $ToPickColumn.id

& git fetch --all 2>&1 | Out-Null

$Entries = @(& git log $SourceBranch --grep "(#\($($Cards.Number -Join "\|")\))" "--pretty=format:%H%x1C%s"  |
    ConvertFrom-CSV -Delimiter "`u{001C}" -Header CommitID,Subject)

[Array]::Reverse($Entries)

$PickArgs = @()
If ($GpgSign) {
    $PickArgs += , "-S"
}

$CommitPRRegex = [Regex]"\(#(\d+)\)$"
$Entries | ForEach-Object {
    Write-Host "`e[96m`e[1;7mPICK`e[22;27m $($_.CommitID): $($_.Subject)`e[m"

Review comment (suggestion):
You could abbreviate that as:
```pwsh
if ($Branch -notmatch "^release-(\d+(\.\d+)+)$") {
```
and use `$Matches.1`.

Code after:

Function Done() {
    $Host.ExitNestedPrompt()
}

Function Abort() {
    $Global:Abort = $True
    $Host.ExitNestedPrompt()
}

Function Skip() {
    $Global:Skip = $True
    $Host.ExitNestedPrompt()
}

Function Reject() {
    $Global:Skip = $True
    $Global:Reject = $True
    $Host.ExitNestedPrompt()
}

If ([String]::IsNullOrEmpty($Version)) {
    $BranchVersionRegex = [Regex]"^release-(\d+(\.\d+)+)$"
    $Branch = & git rev-parse --abbrev-ref HEAD
    $Version = $BranchVersionRegex.Match($Branch).Groups[1].Value
    If ([String]::IsNullOrEmpty($Version)) {
        Write-Error "No version specified, and we can't infer it from the name of your branch ($Branch)."
        Exit 1
    }
    Write-Host "Inferred servicing version $Version"
}

$Script:TodoColumnName = "To Cherry Pick"
$Script:DoneColumnName = "Cherry Picked"
$Script:RejectColumnName = "Rejected"

# Propagate default values into all PSGitHub cmdlets
$PSDefaultParameterValues['*GitHub*:Owner'] = "microsoft"
$PSDefaultParameterValues['*GitHub*:RepositoryName'] = "terminal"

$Project = Get-GithubProject -Name "$Version Servicing Pipeline"
$AllColumns = Get-GithubProjectColumn -ProjectId $Project.id
$ToPickColumn = $AllColumns | ? Name -Eq $script:TodoColumnName
$DoneColumn = $AllColumns | ? Name -Eq $script:DoneColumnName
$RejectColumn = $AllColumns | ? Name -Eq $script:RejectColumnName
$Cards = Get-GithubProjectCard -ColumnId $ToPickColumn.id

& git fetch --all 2>&1 | Out-Null

$Entries = @(& git log $SourceBranch --grep "(#\($($Cards.Number -Join "\|")\))" "--pretty=format:%H%x1C%s"  |
    ConvertFrom-CSV -Delimiter "`u{001C}" -Header CommitID,Subject)