Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools for PR 3250 (#24233)
Browse files Browse the repository at this point in the history
* Change the direction of the commit date

* Log on right place

* remove auth

* fix typo

* Add auth token back

* add delete back

* Update eng/common/scripts/Delete-RemoteBranches.ps1

Co-authored-by: Wes Haggard <[email protected]>

* Update Delete-RemoteBranches.ps1

* Update Delete-RemoteBranches.ps1

* Update Delete-RemoteBranches.ps1

* Update Delete-RemoteBranches.ps1

* Update Delete-RemoteBranches.ps1

Co-authored-by: sima-zhu <[email protected]>
Co-authored-by: Sima Zhu <[email protected]>
Co-authored-by: Wes Haggard <[email protected]>
  • Loading branch information
4 people authored Apr 28, 2022
1 parent a7ecbe1 commit 0a9f2be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions eng/common/scripts/Delete-RemoteBranches.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ foreach ($res in $responses)
continue
}
$branch = $res.ref
$branchName = $branch.Replace("refs/heads/","")
try {
$branchName = $branch.Replace("refs/heads/","")
$head = "${RepoId}:${branchName}"
LogDebug "Operating on branch [ $branchName ]"
$pullRequests = Get-GitHubPullRequests -RepoId $RepoId -State "all" -Head $head -AuthToken $AuthToken
Expand All @@ -53,26 +53,34 @@ foreach ($res in $responses)
continue
}

LogDebug "Branch [ $branchName ] in repo [ $RepoId ] has no associated open Pull Request. "
if ($LastCommitOlderThan) {
if (!$res.object -or !$res.object.url) {
LogWarning "No commit url returned from response. Skipping... "
continue
}
try {
$commitDate = Get-GithubReferenceCommitDate -commitUrl $res.object.url -AuthToken $AuthToken
if ($commitDate -and ($commitDate -gt $LastCommitOlderThan)) {
LogDebug "The branch $branch last commit date $commitDate is newer than the date $LastCommitOlderThan. Skipping."
if (!$commitDate)
{
LogDebug "No last commit date found. Skipping."
continue
}
if ($commitDate -gt $LastCommitOlderThan) {
LogDebug "The branch $branch last commit date [ $commitDate ] is newer than the date $LastCommitOlderThan. Skipping."
continue
}

LogDebug "Branch [ $branchName ] in repo [ $RepoId ] has a last commit date [ $commitDate ] that is older than $LastCommitOlderThan. "
}
catch {
LogError "Get-GithubReferenceCommitDate failed with exception:`n$_"
exit 1
}
}
LogDebug "Branch [ $branchName ] in repo [ $RepoId ] has no associated open Pull Request. "
try {
Remove-GitHubSourceReferences -RepoId $RepoId -Ref $branch -AuthToken $AuthToken
LogDebug "The branch [ $branchName ] in [ $RepoId ] has been deleted."
}
catch {
LogError "Remove-GitHubSourceReferences failed with exception:`n$_"
Expand Down
2 changes: 1 addition & 1 deletion eng/common/scripts/Invoke-GitHubAPI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -429,5 +429,5 @@ function Get-GithubReferenceCommitDate($commitUrl, $AuthToken) {
LogDebug "No date returned from the commit sha. "
return $null
}
return $commitData.committer.date
return $commitResponse.committer.date
}

0 comments on commit 0a9f2be

Please sign in to comment.