-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync eng/common directory with azure-sdk-tools for PR 1088 (#14482)
* Add pipeline configuration for cleaning up upstream branches * Fix powershell naming * Switch to use github API * Use github API to delete branches Co-authored-by: Chidozie Ononiwu <chononiw@microsoft.com>
- Loading branch information
1 parent
d2cfea4
commit 23e3963
Showing
2 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
param( | ||
$RepoOwner, | ||
$RepoName, | ||
$BranchPrefix, | ||
$AuthToken | ||
) | ||
|
||
. "${PSScriptRoot}\common.ps1" | ||
|
||
LogDebug "Operating on Repo [ $RepoName ]" | ||
try{ | ||
$branches = (List-References -RepoOwner $RepoOwner -RepoName $RepoName -Ref "heads/$BranchPrefix").ref | ||
} | ||
catch { | ||
LogError "List-References 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 = List-PullRequests -RepoOwner $RepoOwner -RepoName $RepoName -head $head | ||
} | ||
catch | ||
{ | ||
LogError "List-PullRequests 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{ | ||
Delete-References -RepoOwner $RepoOwner -RepoName $RepoName -Ref ($branch.Remove(0,5)) -AuthToken $AuthToken | ||
} | ||
catch { | ||
LogError "Delete-References failed with exception:`n$_" | ||
exit 1 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters