ReportDiff.ps1 1.7 KB

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