-
Notifications
You must be signed in to change notification settings - Fork 183
/
Copy pathApprove-Eng-Common-Sync-PRs.ps1
64 lines (53 loc) · 1.84 KB
/
Approve-Eng-Common-Sync-PRs.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
[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",
"azure-sdk-for-rust",
"azure-rest-api-specs"
)
foreach ($repo in $repos)
{
$prstate = gh pr view $engCommonSyncBranch -R Azure/$repo --json "url,state,mergeable,mergeStateStatus,reviews" | ConvertFrom-Json
Write-Host "$($prstate.url) - " -NoNewline
if ($prstate.state -eq "MERGED") {
Write-Host "MERGED"
continue
}
if ($prstate.reviews.author.login -notcontains $ghloggedInUser) {
gh pr review $engCommonSyncBranch -R Azure/$repo --approve
# Refresh after approval
$prstate = gh pr view $engCommonSyncBranch -R Azure/$repo --json "url,state,mergeable,mergeStateStatus,reviews" | ConvertFrom-Json
}
else {
Write-Host "Already approved"
}
if ($prstate.mergeStateStatus -ne "CLEAN") {
Write-Host "****PR $($prstate.url) is not mergeable [state: $($prstate.mergeStateStatus)] and may need to be manually merged"
}
}