Skip to content

Commit

Permalink
Add script to help approve eng-common PRs (#9006)
Browse files Browse the repository at this point in the history
  • Loading branch information
weshaggard authored Sep 18, 2024
1 parent da0cc37 commit 7ab4a4b
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions eng/scripts/Approve-Eng-Common-Sync-PRs.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true)]
[string] $engCommonSyncPRNumber

)

gh auth status

if ($LASTEXITCODE -ne 0) {
Write-Error "Please login via gh auth login"
exit 1
}

$ghloggedInUser = (gh api user -q .login)
$engCommonToolsBranch = gh pr view $engCommonSyncPRNumber -R Azure/azure-sdk-tools --json "headRefName" --jq ".headRefName"

if (!$engCommonToolsBranch) {
Write-Error "Didn't find branch for PR $engCommonSyncPRNumber in Azure/azure-sdk-tools"
exit 1
}

# needs to remain in sync with \eng\pipelines\templates\stages\archetype-sdk-tool-repo-sync.yml
$engCommonSyncBranch = "sync-eng/common-${engCommonToolsBranch}-${engCommonSyncPRNumber}"

# needs to remain in sync with \eng\pipelines\eng-common-sync.yml
$repos = @(
"azure-sdk",
"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"
)

foreach ($repo in $repos)
{
$prstate = gh pr view $engCommonSyncBranch -R Azure/$repo --json "url,mergeable,mergeStateStatus,reviews" | ConvertFrom-Json

Write-Host "PR: $($prstate.url) - " -NoNewline
if ($prstate.reviews.author.login -notcontains $ghloggedInUser) {
gh pr review $engCommonSyncBranch -R Azure/$repo --approve
}
else {
Write-Host "Already approved"
}
if ($prstate.mergeStateStatus -ne "CLEAN") {
Write-Host "****PR is not mergeable and may need to be manually merged."
}
}

0 comments on commit 7ab4a4b

Please sign in to comment.