-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRebasePendingPullRequests.ps1
More file actions
29 lines (25 loc) · 1012 Bytes
/
RebasePendingPullRequests.ps1
File metadata and controls
29 lines (25 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
param(
[Parameter(mandatory=$true)]$Account,
[Parameter(mandatory=$true)]$AccessToken,
[Parameter(mandatory=$true)]$RepositoryId,
$GitRepositoryUrl = $env:BUILD_REPOSITORY_URI
)
Import-Module (Join-Path $PSScriptRoot "VisualStudioOnline")
Import-Module (Join-Path $PSScriptRoot "GitCommon")
Initialize-Git
$remoteUrl = (Invoke-Git config remote.origin.url -ReturnOutput)
try
{
Initialize-GitRemoteWithCredentials -GitUserName "Unused" -GitAccessToken $AccessToken -GitRepositoryUrl $GitRepositoryUrl
$AuthHeader = (Get-AuthorizationHeader -AccessToken $AccessToken)
(Get-ActivePullRequests -Account $Account -AuthorizationHeader $AuthHeader -RepositoryId $RepositoryId) | %{
[PSCustomObject]@{
SourceRef = ($_.sourceRefName -replace "refs/heads/","");
TargetBranch = ($_.targetRefName -replace "refs/heads/","");
}
} | Invoke-GitRebaseAndUpdateRemote
}
finally
{
Invoke-Git config remote.origin.url "$($remoteUrl)"
}