Browse Source

Avoid sending a PR if there's already one open (#38880)

Chris Ross 4 years ago
parent
commit
e7f0a5c6e4
2 changed files with 29 additions and 4 deletions
  1. 26 1
      .github/workflows/ReportDiff.ps1
  2. 3 3
      .github/workflows/runtime-sync.yml

+ 26 - 1
.github/workflows/ReportDiff.ps1

@@ -26,4 +26,29 @@ $diff
 $json = ConvertTo-Json -InputObject @{ 'body' = $body }
 $issue = $issue + '/comments'
 $result = Invoke-RestMethod -Method POST -Headers $Headers -Uri $issue -Body $json
-return $changed
+
+# Check if there's an open PR in AspNetCore or Runtime to resolve this difference.
+$sendpr = $true
+$Headers = @{ Accept = 'application/vnd.github.v3+json' };
+
+$prsLink = "https://api.github.com/repos/dotnet/aspnetcore/pulls?state=open"
+$result = Invoke-RestMethod -Method GET -Headers $Headers -Uri $prsLink
+
+foreach ($pr in $result) {
+  if ($pr.body -And $pr.body.Contains("Fixes #18943")) {
+    $sendpr = $false
+    return $sendpr
+  }
+}
+
+$prsLink = "https://api.github.com/repos/dotnet/runtime/pulls?state=open"
+$result = Invoke-RestMethod -Method GET -Headers $Headers -Uri $prsLink
+
+foreach ($pr in $result) {
+  if ($pr.body -And $pr.body.Contains("Fixes https://github.com/dotnet/aspnetcore/issues/18943")) {
+    $sendpr = $false
+    return $sendpr
+  }
+}
+
+return $sendpr

+ 3 - 3
.github/workflows/runtime-sync.yml

@@ -59,10 +59,10 @@ jobs:
       run: |
         # Test this script using an issue in the local forked repo
         $issue = 'https://api.github.com/repos/dotnet/aspnetcore/issues/18943'
-        $changed = .\aspnetcore\.github\workflows\ReportDiff.ps1
-        echo "::set-output name=changed::$changed"
+        $sendpr = .\aspnetcore\.github\workflows\ReportDiff.ps1
+        echo "::set-output name=sendpr::$sendpr"
     - name: Send PR
-      if: steps.check.outputs.changed == 'true'
+      if: steps.check.outputs.sendpr == 'true'
       # https://github.com/marketplace/actions/create-pull-request
       uses: dotnet/actions-create-pull-request@v3
       with: