Skip to content

Commit

Permalink
Add pipeline configuration for cleaning up upstream branches
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu committed Oct 12, 2020
1 parent 49b1b81 commit 4992fbe
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
43 changes: 43 additions & 0 deletions eng/common/scripts/Delete-Remote-Branches.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
param(
$RepoOwner,
$RepoName,
$BranchPrefix,
$WorkingDirectory,
$AuthToken
)

. "${PSScriptRoot}\common.ps1"

pushd $WorkingDirectory
git clone https://github.com/$RepoOwner/$RepoName.git
pushd $RepoName
$syncBranches = git branch -r --list origin/$BranchPrefix* | % { $_ -replace "origin/", "" }

LogDebug "Operating on Repo [ $RepoName ]"
foreach ($branch in $syncBranches)
{
try {
$branchName = $branch.Trim()
$head = "${RepoOwner}/${RepoName}:${branchName}"
LogDebug "Operating on branch [ $branchName ]"
$response = ListPullRequests -RepoOwner $RepoOwner -RepoName $RepoName -head $head
}
catch
{
LogError "ListPullRequests failed with exception:`n$_"
exit 1
}

if ($response.Count -eq 0)
{
LogDebug "Branch [ $branchName ] in repo [ $RepoName ] has no associated Pull Request. Deleting Branch"
git push origin --delete $branchName
if ($lastExitCode -ne 0) {
Write-Host "Failed to delete branch [ $branchName ] in repo [ $RepoName ]"
exit 1
}
}
}

popd
popd
32 changes: 32 additions & 0 deletions eng/pipelines/templates/jobs/tools-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
parameters:
- name: Repos
type: object
default:
- azure-sdk-for-android
- azure-sdk-for-c
- azure-sdk-for-cpp
- azure-sdk-for-go
- azure-sdk-for-ios
- azure-sdk-for-java
- azure-sdk-for-js
- azure-sdk-for-net
- azure-sdk-for-python

jobs:
- job: CleanUp
pool:
vmImage: windows-2019
steps:
- ${{ each repo in parameters.Repos }}:
- task: PowerShell@2
displayName: Clean Up Sync Common Branches
condition: succeeded()
inputs:
pwsh: true
workingDirectory: $(System.DefaultWorkingDirectory)
filePath: $(System.DefaultWorkingDirectory)/eng/common/scripts/Delete-Remote-Branches.ps1
arguments: >
-RepoName ${{ repo }}
-BranchPrefix "sync-eng/common-"
-WorkingDirectory $(System.DefaultWorkingDirectory)
-AuthToken $(azuresdk-github-pat)

0 comments on commit 4992fbe

Please sign in to comment.