-
Notifications
You must be signed in to change notification settings - Fork 10k
/
ReportDiff.ps1
57 lines (49 loc) · 1.65 KB
/
ReportDiff.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
# Check the code is in sync
$changed = (select-string "nothing to commit" artifacts\status.txt).count -eq 0
if (-not $changed) { return $changed }
# Check if tracking issue is open/closed
$Headers = @{
Authorization = 'token {0}' -f $ENV:GITHUB_TOKEN;
'Content-Type' = 'application/json'
};
$result = Invoke-RestMethod -Uri $issue
if ($result.state -eq "closed") {
$json = "{ `"state`": `"open`" }"
$result = Invoke-RestMethod -Method PATCH -Headers $Headers -Uri $issue -Body $json
}
# Add a comment
$status = [IO.File]::ReadAllText("artifacts\status.txt")
$diff = [IO.File]::ReadAllText("artifacts\diff.txt")
$body = @"
The shared code is out of sync.
<details>
<summary>The Diff</summary>
``````
$status
$diff
``````
</details>
"@
$json = ConvertTo-Json -InputObject @{ 'body' = $body }
$issue = $issue + '/comments'
$result = Invoke-RestMethod -Method POST -Headers $Headers -Uri $issue -Body $json
# 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