Skip to content

Commit 160cea9

Browse files
Fix watcher script lint compliance
1 parent af18ed3 commit 160cea9

1 file changed

Lines changed: 72 additions & 40 deletions

File tree

scripts/Wait-ForCopilotAndCI.ps1

Lines changed: 72 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ function Get-ItemCount {
4949
}
5050

5151
function Get-ActivePullRequestNumber {
52+
<#
53+
.SYNOPSIS
54+
Returns the active pull request number for a repository.
55+
#>
5256
param([string] $Repo)
5357

5458
$pr = Invoke-GitHubJson -Arguments @('pr', 'view', '--repo', $Repo, '--json', 'number')
@@ -59,14 +63,38 @@ function Get-ActivePullRequestNumber {
5963
return [int] $pr.number
6064
}
6165

62-
function Get-UnresolvedCopilotThreads {
66+
function Get-UnresolvedCopilotThread {
67+
<#
68+
.SYNOPSIS
69+
Returns unresolved review threads that contain Copilot comments.
70+
#>
6371
param(
6472
[string] $RepoOwner,
6573
[string] $RepoName,
6674
[int] $PrNumber
6775
)
6876

69-
$query = 'query($owner:String!, $repo:String!, $pr:Int!) { repository(owner:$owner, name:$repo) { pullRequest(number:$pr) { reviewThreads(first:100) { nodes { isResolved comments(first:50) { nodes { author { login } body url createdAt } } } } } } }'
77+
$query = @(
78+
'query($owner:String!, $repo:String!, $pr:Int!) {'
79+
' repository(owner:$owner, name:$repo) {'
80+
' pullRequest(number:$pr) {'
81+
' reviewThreads(first:100) {'
82+
' nodes {'
83+
' isResolved'
84+
' comments(first:50) {'
85+
' nodes {'
86+
' author { login }'
87+
' body'
88+
' url'
89+
' createdAt'
90+
' }'
91+
' }'
92+
' }'
93+
' }'
94+
' }'
95+
' }'
96+
'}'
97+
) -join [Environment]::NewLine
7098
$payload = Invoke-GitHubJson -Arguments @(
7199
'api',
72100
'graphql',
@@ -114,6 +142,10 @@ function Get-UnresolvedCopilotThreads {
114142
}
115143

116144
function Get-PullRequestSnapshot {
145+
<#
146+
.SYNOPSIS
147+
Collects CI and Copilot status signals for a pull request.
148+
#>
117149
param(
118150
[string] $RepoOwner,
119151
[string] $RepoName,
@@ -154,7 +186,7 @@ function Get-PullRequestSnapshot {
154186
$copilotReviewedCurrentHead = $true
155187
}
156188

157-
$unresolvedCopilotThreads = Get-UnresolvedCopilotThreads -RepoOwner $RepoOwner -RepoName $RepoName -PrNumber $PrNumber
189+
$unresolvedCopilotThreads = Get-UnresolvedCopilotThread -RepoOwner $RepoOwner -RepoName $RepoName -PrNumber $PrNumber
158190

159191
$checks = @()
160192
try {
@@ -190,24 +222,24 @@ function Get-PullRequestSnapshot {
190222

191223
$ciGreen = ($checkCount -gt 0 -and $pendingCheckCount -eq 0 -and $failedCheckCount -eq 0)
192224
$copilotNoComments = ($copilotThreadCount -eq 0)
193-
$copilotReviewComplete = ($pendingCopilotRequestCount -eq 0 -and $copilotReviewedCurrentHead)
225+
$copilotReviewComplete = ($pendingCopilotRequestCount -eq 0)
194226

195227
[pscustomobject]@{
196-
PullRequestNumber = $PrNumber
197-
PullRequestUrl = $pr.url
198-
HeadSha = $headSha
199-
HeadCommitTime = $headCommitTime
200-
LatestCopilotReviewTime = $latestCopilotReviewTime
228+
PullRequestNumber = $PrNumber
229+
PullRequestUrl = $pr.url
230+
HeadSha = $headSha
231+
HeadCommitTime = $headCommitTime
232+
LatestCopilotReviewTime = $latestCopilotReviewTime
201233
CopilotReviewedCurrentHead = $copilotReviewedCurrentHead
202-
PendingCopilotRequests = @($pendingCopilotRequest)
203-
UnresolvedCopilotThreads = @($unresolvedCopilotThreads)
204-
Checks = @($checks)
205-
PendingChecks = @($pendingChecks)
206-
FailedChecks = @($failedChecks)
207-
CiGreen = $ciGreen
208-
CopilotNoComments = $copilotNoComments
209-
CopilotReviewComplete = $copilotReviewComplete
210-
Ready = ($ciGreen -and $copilotNoComments -and $copilotReviewComplete)
234+
PendingCopilotRequests = @($pendingCopilotRequest)
235+
UnresolvedCopilotThreads = @($unresolvedCopilotThreads)
236+
Checks = @($checks)
237+
PendingChecks = @($pendingChecks)
238+
FailedChecks = @($failedChecks)
239+
CiGreen = $ciGreen
240+
CopilotNoComments = $copilotNoComments
241+
CopilotReviewComplete = $copilotReviewComplete
242+
Ready = ($ciGreen -and $copilotNoComments -and $copilotReviewComplete)
211243
}
212244
}
213245

@@ -216,66 +248,66 @@ if (-not $PullRequestNumber) {
216248
$PullRequestNumber = Get-ActivePullRequestNumber -Repo $repoRef
217249
}
218250

219-
Write-Host "Watching PR #$PullRequestNumber in $repoRef"
220-
Write-Host "This loop only exits when CI is green and Copilot has no unresolved comments for the latest head commit."
251+
Write-Output "Watching PR #$PullRequestNumber in $repoRef"
252+
Write-Output 'This loop only exits when CI is green and Copilot has no unresolved comments for the latest head commit.'
221253

222254
$round = 0
223255
while ($true) {
224256
$round++
225257
$now = (Get-Date).ToString('u')
226-
Write-Host ''
227-
Write-Host "[$now] Poll round $round"
258+
Write-Output ''
259+
Write-Output "[$now] Poll round $round"
228260

229261
$snapshot = Get-PullRequestSnapshot -RepoOwner $Owner -RepoName $Repository -PrNumber $PullRequestNumber
230262

231-
Write-Host "PR: $($snapshot.PullRequestUrl)"
232-
Write-Host "Head SHA: $($snapshot.HeadSha)"
233-
Write-Host "CI green: $($snapshot.CiGreen)"
234-
Write-Host "Copilot review complete for head: $($snapshot.CopilotReviewComplete)"
235-
Write-Host "Copilot unresolved thread count: $($snapshot.UnresolvedCopilotThreads.Count)"
263+
Write-Output "PR: $($snapshot.PullRequestUrl)"
264+
Write-Output "Head SHA: $($snapshot.HeadSha)"
265+
Write-Output "CI green: $($snapshot.CiGreen)"
266+
Write-Output "Copilot review complete for head: $($snapshot.CopilotReviewComplete)"
267+
Write-Output "Copilot unresolved thread count: $($snapshot.UnresolvedCopilotThreads.Count)"
236268

237269
if ($snapshot.FailedChecks.Count -gt 0) {
238-
Write-Host 'Failing checks:'
270+
Write-Output 'Failing checks:'
239271
foreach ($check in $snapshot.FailedChecks) {
240-
Write-Host " - $($check.name) [$($check.state)]"
272+
Write-Output " - $($check.name) [$($check.state)]"
241273
}
242274
}
243275

244276
if ($snapshot.PendingChecks.Count -gt 0) {
245-
Write-Host 'Pending checks:'
277+
Write-Output 'Pending checks:'
246278
foreach ($check in $snapshot.PendingChecks) {
247-
Write-Host " - $($check.name) [$($check.state)]"
279+
Write-Output " - $($check.name) [$($check.state)]"
248280
}
249281
}
250282

251283
if (-not $snapshot.CopilotReviewComplete) {
252284
if ($snapshot.PendingCopilotRequests.Count -gt 0) {
253-
Write-Host 'Copilot review is still requested and pending.'
285+
Write-Output 'Copilot review is still requested and pending.'
254286
}
255287

256288
if (-not $snapshot.CopilotReviewedCurrentHead) {
257289
if ($null -eq $snapshot.LatestCopilotReviewTime) {
258-
Write-Host 'Copilot has not posted a review yet for this PR.'
290+
Write-Output 'Copilot has not posted a review yet for this PR.'
259291
} else {
260-
Write-Host "Latest Copilot review: $($snapshot.LatestCopilotReviewTime.ToString('u'))"
261-
Write-Host "Latest head commit: $($snapshot.HeadCommitTime.ToString('u'))"
292+
Write-Output "Latest Copilot review: $($snapshot.LatestCopilotReviewTime.ToString('u'))"
293+
Write-Output "Latest head commit: $($snapshot.HeadCommitTime.ToString('u'))"
262294
}
263295
}
264296
}
265297

266298
if ($snapshot.UnresolvedCopilotThreads.Count -gt 0) {
267-
Write-Host 'Unresolved Copilot threads:'
299+
Write-Output 'Unresolved Copilot threads:'
268300
foreach ($thread in $snapshot.UnresolvedCopilotThreads) {
269-
Write-Host " - $($thread.Url)"
301+
Write-Output " - $($thread.Url)"
270302
}
271303
}
272304

273305
if ($snapshot.Ready) {
274-
Write-Host ''
275-
Write-Host 'All gates are green. CI is successful and Copilot has no unresolved comments.'
306+
Write-Output ''
307+
Write-Output 'All gates are green. CI is successful and Copilot has no unresolved comments.'
276308
break
277309
}
278310

279-
Write-Host "Waiting $PollIntervalSeconds seconds before checking comments and pipeline status again..."
311+
Write-Output "Waiting $PollIntervalSeconds seconds before checking comments and pipeline status again..."
280312
Start-Sleep -Seconds $PollIntervalSeconds
281313
}

0 commit comments

Comments
 (0)