Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into Rename-TimeoutSec-t…
Browse files Browse the repository at this point in the history
…o-ConnectTimeoutSec-and-alias-to-TimeoutSec-and-add-NetworkTimeoutSec-timeout
  • Loading branch information
stevenebutler committed Apr 27, 2023
2 parents 9d6184a + 6e34b1b commit 82ab2b6
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 244 deletions.
66 changes: 0 additions & 66 deletions .github/workflows/backport.yml

This file was deleted.

1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Andy Jordan <andy.jordan@microsoft.com> <andrew@schwartzmeyer.com>
20 changes: 0 additions & 20 deletions tools/actions/backport/action.yml

This file was deleted.

157 changes: 0 additions & 157 deletions tools/actions/backport/index.js

This file was deleted.

84 changes: 83 additions & 1 deletion tools/releaseTools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -724,4 +724,86 @@ function Get-PRBackportReport {
}
}

Export-ModuleMember -Function Get-ChangeLog, Get-NewOfficalPackage, Update-PsVersionInCode, Get-PRBackportReport
# Backports a PR
# requires:
# * a remote called upstream pointing to powershell/powershell
# * the github cli installed and authenticated
# Usage:
# Invoke-PRBackport -PRNumber 1234 -Target release/v7.0.1
# To overwrite a local branch add -Overwrite
# To add an postfix to the branch name use -BranchPostFix <postfix>
function Invoke-PRBackport {
[cmdletbinding(SupportsShouldProcess, ConfirmImpact = 'High')]
param(
[Parameter(Mandatory)]
[string]
$PrNumber,

[Parameter(Mandatory)]
[ValidateScript({$_ -match '^release/v\d+\.\d+\.\d+'})]
[string]
$Target,

[switch]
$Overwrite,

[string]
$BranchPostFix
)
function script:Invoke-NativeCommand {
param(
[scriptblock] $ScriptBlock
)
&$ScriptBlock
if ($LASTEXITCODE -ne 0) {
throw "$ScriptBlock fail with $LASTEXITCODE"
}
}
$ErrorActionPreference = 'stop'

$pr = gh pr view $PrNumber --json 'mergeCommit,state,title' | ConvertFrom-Json

$commitId = $pr.mergeCommit.oid
$state = $pr.state
$originaltitle = $pr.title
$backportTitle = "[$Target]$originalTitle"

Write-Verbose -Verbose "commitId: $commitId; state: $state"
Write-Verbose -Verbose "title:$backportTitle"

if ($state -ne 'MERGED') {
throw "PR is not merged ($state)"
}

$upstream = $null
$upstreamName = 'powershell/powershell'
$upstream = Invoke-NativeCommand { git remote -v } | Where-Object { $_ -match "^upstream.*$upstreamName.*fetch" }

if (!$upstream) {
throw "Please create an upstream remote that points to $upstreamName"
}

Invoke-NativeCommand { git fetch upstream $Target }

$switch = '-c'
if ($Overwrite) {
$switch = '-C'
}

$branchName = "backport-$PrNumber"
if ($BranchPostFix) {
$branchName += "-$BranchPostFix"
}

if ($PSCmdlet.ShouldProcess("Create branch $branchName from upstream/$Target")) {
Invoke-NativeCommand { git switch upstream/$Target $switch $branchName }
}

Invoke-NativeCommand { git cherry-pick $commitId }

if ($PSCmdlet.ShouldProcess("Create the PR")) {
gh pr create --base $Target --title $backportTitle --body "Backport #$PrNumber"
}
}

Export-ModuleMember -Function Get-ChangeLog, Get-NewOfficalPackage, Update-PsVersionInCode, Get-PRBackportReport, Invoke-PRBackport

0 comments on commit 82ab2b6

Please sign in to comment.