Update Delete-RemoteBranches.ps1 (#849)
Co-authored-by: Chidozie Ononiwu <chononiw@microsoft.com>
This commit is contained in:
parent
ef15be36af
commit
a09ceeaa01
@ -9,7 +9,7 @@ param(
|
||||
|
||||
LogDebug "Operating on Repo [ $RepoName ]"
|
||||
try{
|
||||
$branches = (Get-GitHubSourceReferences -RepoOwner $RepoOwner -RepoName $RepoName -Ref "heads/$BranchPrefix").ref
|
||||
$branches = (Get-GitHubSourceReferences -RepoOwner $RepoOwner -RepoName $RepoName -Ref "heads/$BranchPrefix" -AuthToken $AuthToken).ref
|
||||
}
|
||||
catch {
|
||||
LogError "Get-GitHubSourceReferences failed with exception:`n$_"
|
||||
@ -22,7 +22,7 @@ foreach ($branch in $branches)
|
||||
$branchName = $branch.Replace("refs/heads/","")
|
||||
$head = "${RepoOwner}/${RepoName}:${branchName}"
|
||||
LogDebug "Operating on branch [ $branchName ]"
|
||||
$pullRequests = Get-GitHubPullRequests -RepoOwner $RepoOwner -RepoName $RepoName -head $head
|
||||
$pullRequests = Get-GitHubPullRequests -RepoOwner $RepoOwner -RepoName $RepoName -State "all" -Head $head -AuthToken $AuthToken
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -30,9 +30,9 @@ foreach ($branch in $branches)
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ($pullRequests.Count -eq 0)
|
||||
if ($pullRequests -and (($pullRequests | ? { $_.State -eq "open" }).Count -eq 0))
|
||||
{
|
||||
LogDebug "Branch [ $branchName ] in repo [ $RepoName ] has no associated Pull Request. Deleting Branch"
|
||||
LogDebug "Branch [ $branchName ] in repo [ $RepoName ] has no associated open Pull Request. Deleting Branch"
|
||||
try{
|
||||
Remove-GitHubSourceReferences -RepoOwner $RepoOwner -RepoName $RepoName -Ref ($branch.Remove(0,5)) -AuthToken $AuthToken
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user