From e788cf6303aaf14a3170e34956a806590331c6ef Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Thu, 28 Apr 2022 12:51:29 -0700 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools for PR 3250 (#3595) * 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 * 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 Co-authored-by: Sima Zhu <48036328+sima-zhu@users.noreply.github.com> Co-authored-by: Wes Haggard --- eng/common/scripts/Delete-RemoteBranches.ps1 | 16 ++++++++++++---- eng/common/scripts/Invoke-GitHubAPI.ps1 | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/eng/common/scripts/Delete-RemoteBranches.ps1 b/eng/common/scripts/Delete-RemoteBranches.ps1 index 6b5e17030..4ee3f1b05 100644 --- a/eng/common/scripts/Delete-RemoteBranches.ps1 +++ b/eng/common/scripts/Delete-RemoteBranches.ps1 @@ -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 @@ -53,6 +53,7 @@ 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... " @@ -60,19 +61,26 @@ foreach ($res in $responses) } 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$_" diff --git a/eng/common/scripts/Invoke-GitHubAPI.ps1 b/eng/common/scripts/Invoke-GitHubAPI.ps1 index 6f02d2edc..0bc2e871c 100644 --- a/eng/common/scripts/Invoke-GitHubAPI.ps1 +++ b/eng/common/scripts/Invoke-GitHubAPI.ps1 @@ -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 }