azure-sdk-for-cpp/eng/common/scripts/Delete-RemoteBranches.ps1
Azure SDK Bot 50a1354aaf
Sync eng/common directory with azure-sdk-tools for PR 1091 (#790)
* Refactpr Submit Pull Request Script

* Refactor logic for interacting with Pull Requests

* Rework API Lib

Co-authored-by: Chidozie Ononiwu <chononiw@microsoft.com>
2020-10-16 13:06:31 -07:00

44 lines
1.1 KiB
PowerShell

param(
$RepoOwner,
$RepoName,
$BranchPrefix,
$AuthToken
)
. "${PSScriptRoot}\common.ps1"
LogDebug "Operating on Repo [ $RepoName ]"
try{
$branches = (Get-GitHubSourceReferences -RepoOwner $RepoOwner -RepoName $RepoName -Ref "heads/$BranchPrefix").ref
}
catch {
LogError "Get-GitHubSourceReferences failed with exception:`n$_"
exit 1
}
foreach ($branch in $branches)
{
try {
$branchName = $branch.Replace("refs/heads/","")
$head = "${RepoOwner}/${RepoName}:${branchName}"
LogDebug "Operating on branch [ $branchName ]"
$pullRequests = Get-GitHubPullRequests -RepoOwner $RepoOwner -RepoName $RepoName -head $head
}
catch
{
LogError "Get-GitHubPullRequests failed with exception:`n$_"
exit 1
}
if ($pullRequests.Count -eq 0)
{
LogDebug "Branch [ $branchName ] in repo [ $RepoName ] has no associated Pull Request. Deleting Branch"
try{
Remove-GitHubSourceReferences -RepoOwner $RepoOwner -RepoName $RepoName -Ref ($branch.Remove(0,5)) -AuthToken $AuthToken
}
catch {
LogError "Remove-GitHubSourceReferences failed with exception:`n$_"
exit 1
}
}
}