ReportDiff.ps1 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Check the code is in sync
  2. $changed = (select-string "nothing to commit" artifacts\status.txt).count -eq 0
  3. if (-not $changed) { return $changed }
  4. # Check if tracking issue is open/closed
  5. $Headers = @{ Authorization = 'token {0}' -f $ENV:GITHUB_TOKEN; };
  6. $result = Invoke-RestMethod -Uri $issue
  7. if ($result.state -eq "closed") {
  8. $json = "{ `"state`": `"open`" }"
  9. $result = Invoke-RestMethod -Method PATCH -Headers $Headers -Uri $issue -Body $json
  10. }
  11. # Add a comment
  12. $status = [IO.File]::ReadAllText("artifacts\status.txt")
  13. $diff = [IO.File]::ReadAllText("artifacts\diff.txt")
  14. $body = @"
  15. The shared code is out of sync.
  16. <details>
  17. <summary>The Diff</summary>
  18. ``````
  19. $status
  20. $diff
  21. ``````
  22. </details>
  23. "@
  24. $json = ConvertTo-Json -InputObject @{ 'body' = $body }
  25. $issue = $issue + '/comments'
  26. $result = Invoke-RestMethod -Method POST -Headers $Headers -Uri $issue -Body $json
  27. # Check if there's an open PR in AspNetCore or Runtime to resolve this difference.
  28. $sendpr = $true
  29. $Headers = @{ Accept = 'application/vnd.github.v3+json' };
  30. $prsLink = "https://api.github.com/repos/dotnet/aspnetcore/pulls?state=open"
  31. $result = Invoke-RestMethod -Method GET -Headers $Headers -Uri $prsLink
  32. foreach ($pr in $result) {
  33. if ($pr.body -And $pr.body.Contains("Fixes #18943")) {
  34. $sendpr = $false
  35. return $sendpr
  36. }
  37. }
  38. $prsLink = "https://api.github.com/repos/dotnet/runtime/pulls?state=open"
  39. $result = Invoke-RestMethod -Method GET -Headers $Headers -Uri $prsLink
  40. foreach ($pr in $result) {
  41. if ($pr.body -And $pr.body.Contains("Fixes https://github.com/dotnet/aspnetcore/issues/18943")) {
  42. $sendpr = $false
  43. return $sendpr
  44. }
  45. }
  46. return $sendpr