From a8b0427da659b63a74866bccf58f2beb0ab4bfe5 Mon Sep 17 00:00:00 2001 From: MiyakoMeow <110924386+MiyakoMeow@users.noreply.github.com> Date: Tue, 3 Mar 2026 20:25:16 +0800 Subject: [PATCH 1/7] feat: use graphql for querying --- src/Action/Issue.psm1 | 101 +++++++++++++++++++++-- src/Github.psm1 | 186 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 280 insertions(+), 7 deletions(-) diff --git a/src/Action/Issue.psm1 b/src/Action/Issue.psm1 index 239b10c..13f5ce6 100644 --- a/src/Action/Issue.psm1 +++ b/src/Action/Issue.psm1 @@ -1,6 +1,44 @@ Join-Path $PSScriptRoot '..\Helpers.psm1' | Import-Module Join-Path $PSScriptRoot 'Issue' | Get-ChildItem -Filter '*.psm1' | Select-Object -ExpandProperty Fullname | Import-Module +function Invoke-GithubGraphQLQuery { + <# + .SYNOPSIS + Execute a GraphQL query to GitHub API. + .PARAMETER Query + GraphQL query string. + .PARAMETER Variables + Hashtable of variables for the query. + #> + param( + [Parameter(Mandatory)] + [String] $Query, + [Hashtable] $Variables + ) + + $graphqlUrl = 'https://api.github.com/graphql' + $body = @{ 'query' = $Query } + if ($Variables) { $body['variables'] = $Variables } + + $parameters = @{ + 'Headers' = @{ + 'Authorization' = "Bearer $env:GITHUB_TOKEN" + 'Accept' = 'application/json' + } + 'Method' = 'Post' + 'Uri' = $graphqlUrl + 'Body' = (ConvertTo-Json $body -Depth 10) + 'ContentType' = 'application/json' + } + + Write-Log 'GraphQL Request' $parameters.Uri + + $response = Invoke-WebRequest @parameters + $env:GH_REQUEST_COUNTER = ([int] $env:GH_REQUEST_COUNTER) + 1 + + return $response +} + function Test-Hash { param ( [Parameter(Mandatory = $true)] @@ -63,12 +101,56 @@ function Test-Hash { } else { Write-Log 'Hash mismatch confirmed.' - $masterBranch = ((Invoke-GithubRequest "repos/$REPOSITORY").Content | ConvertFrom-Json).default_branch + # Use GraphQL to fetch repository info and PRs in parallel + $owner, $repo = $REPOSITORY -split '/' + $graphqlQuery = @" + query(`$owner:String!, `$repo:String!) { + repository(owner:`$owner, name:`$repo) { + defaultBranchRef { + name + } + pullRequests(states:OPEN, first:100, orderBy:{field:UPDATED_AT, direction:DESC}) { + nodes { + number + title + body + } + } + } + rateLimit { + remaining + } + } +"@ + + $masterBranch = $null + $prs = $null + + try { + Write-Log 'Attempting GraphQL query for repository and PRs...' + $response = Invoke-GithubGraphQLQuery -Query $graphqlQuery -Variables @{ + owner = $owner + repo = $repo + } + + $content = $response.Content | ConvertFrom-Json + if ($content.data -and $content.data.repository) { + $masterBranch = $content.data.repository.defaultBranchRef.name + $prs = $content.data.repository.pullRequests.nodes + Write-Log "GraphQL query succeeded. Remaining rate limit: $($content.data.rateLimit.remaining)" + } else { + throw 'GraphQL returned no data' + } + } catch { + Write-Log "GraphQL query failed, falling back to REST API: $($_.Exception.Message)" + # Fallback to REST API + $masterBranch = ((Invoke-GithubRequest "repos/$REPOSITORY").Content | ConvertFrom-Json).default_branch + $prs = (Invoke-GithubRequest "repos/$REPOSITORY/pulls?state=open&base=$masterBranch&sorting=updated").Content | ConvertFrom-Json + } + $message = @('You are right. Thank you for reporting.') # TODO: Post labels at the end of function Add-Label -ID $IssueID -Label 'verified', 'hash-fix-needed' - $prs = (Invoke-GithubRequest "repos/$REPOSITORY/pulls?state=open&base=$masterBranch&sorting=updated").Content | ConvertFrom-Json - $titleToBePosted = "$manifestNameAsInBucket@$($man.version): Fix hash" $prs = $prs | Where-Object { $_.title -eq $titleToBePosted } # There is alreay PR for @@ -88,9 +170,16 @@ function Test-Hash { Invoke-GithubRequest "repos/$REPOSITORY/pulls/$prID" -Method Patch -Body @{ 'body' = (@("- Closes #$IssueID", $pr.body) -join "`r`n") } Add-Label -ID $IssueID -Label 'duplicate' } else { - # Check if default branch is protected - if (((Invoke-GithubRequest "repos/$REPOSITORY/branches/$masterBranch").Content | ConvertFrom-Json).protected) { - Write-Log 'PR - Create new branch and post PR' + # Check if default branch is protected (need REST API for this as GraphQL doesn't expose it) + $isProtected = $false + try { + $isProtected = ((Invoke-GithubRequest "repos/$REPOSITORY/branches/$masterBranch").Content | ConvertFrom-Json).protected + } catch { + Write-Log "Failed to check branch protection status: $($_.Exception.Message)" + $isProtected = $false + } + + if ($isProtected) { $branch = "$manifestNameAsInBucket-hash-fix-$(Get-Random -Maximum 258258258)" diff --git a/src/Github.psm1 b/src/Github.psm1 index abd5133..236b7c3 100644 --- a/src/Github.psm1 +++ b/src/Github.psm1 @@ -1,5 +1,189 @@ Join-Path $PSScriptRoot 'Helpers.psm1' | Import-Module +function Invoke-GithubGraphQL { + <# + .SYNOPSIS + Invoke authenticated GitHub GraphQL API request with parallel query support and fallback. + .PARAMETER Query + GraphQL query string. + .PARAMETER Variables + Hashtable of variables for the GraphQL query. + .PARAMETER UseFallback + If set, falls back to REST API on GraphQL failure. + .PARAMETER MaxRetries + Maximum number of retry attempts on rate limit. Default is 3. + .EXAMPLE + Invoke-GithubGraphQL -Query 'query { viewer { login } }' + #> + param( + [Parameter(Mandatory, ValueFromPipeline)] + [String] $Query, + [Hashtable] $Variables, + [Switch] $UseFallback, + [Int] $MaxRetries = 3 + ) + + $graphqlUrl = 'https://api.github.com/graphql' + $retryCount = 0 + $success = $false + $response = $null + + while ($retryCount -lt $MaxRetries -and -not $success) { + try { + $body = @{ + 'query' = $Query + } + if ($Variables) { + $body['variables'] = $Variables + } + + $parameters = @{ + 'Headers' = @{ + 'Authorization' = "Bearer $env:GITHUB_TOKEN" + 'Accept' = 'application/json' + } + 'Method' = 'Post' + 'Uri' = $graphqlUrl + 'Body' = (ConvertTo-Json $body -Depth 10) + 'ContentType' = 'application/json' + } + + Write-Log 'GraphQL Request' $parameters.Uri + Write-Log 'GraphQL Query' $Query + + $response = Invoke-WebRequest @parameters + $content = $response.Content | ConvertFrom-Json + + if ($content.errors) { + Write-Log 'GraphQL Errors' ($content.errors | ConvertTo-Json -Depth 10) + + # Check for rate limit errors + $isRateLimit = $content.errors | Where-Object { $_.type -eq 'RATE_LIMITED' } + if ($isRateLimit) { + $retryCount++ + if ($retryCount -lt $MaxRetries) { + $waitTime = [Math]::Pow(2, $retryCount) * 3 + Write-Log "Rate limit hit, waiting $waitTime seconds before retry ($retryCount/$MaxRetries)" + Start-Sleep -Seconds $waitTime + continue + } else { + throw "Rate limit exceeded after $MaxRetries retries" + } + } + + throw "GraphQL query failed: $($content.errors[0].message)" + } + + $env:GH_REQUEST_COUNTER = ([int] $env:GH_REQUEST_COUNTER) + 1 + $success = $true + + return $response + } catch { + Write-Log "GraphQL request failed: $($_.Exception.Message)" + + $retryCount++ + if ($retryCount -lt $MaxRetries -and $_.Exception.Message -match 'rate limit|timeout|temporary') { + $waitTime = [Math]::Pow(2, $retryCount) * 3 + Write-Log "Retrying in $waitTime seconds..." + Start-Sleep -Seconds $waitTime + } else { + throw + } + } + } + + if (-not $success) { + throw "GraphQL request failed after $MaxRetries retries: $($response | Out-String)" + } +} + +function Invoke-GithubGraphQLParallel { + <# + .SYNOPSIS + Execute multiple GraphQL queries in parallel to avoid rate limits. + .PARAMETER Queries + Array of hashtables containing Query and Variables. + .PARAMETER UseFallback + If set, falls back to REST API on GraphQL failure. + .EXAMPLE + $queries = @( + @{ Query = 'query($owner:String!, $name:String!) { repository(owner:$owner, name:$name) { defaultBranch } }'; Variables = @{ owner = 'octocat'; name = 'Hello-World' } } + ) + Invoke-GithubGraphQLParallel -Queries $queries + #> + param( + [Parameter(Mandatory)] + [Hashtable[]] $Queries, + [Switch] $UseFallback + ) + + $results = @() + $errors = @() + + # Use Runspaces for parallel execution + $runspacePool = [runspacefactory]::CreateRunspacePool(1, [Math]::Min(5, $Queries.Count)) + $runspacePool.Open() + + $jobs = @() + foreach ($q in $Queries) { + $powershell = [powershell]::Create() + $powershell.RunspacePool = $runspacePool + $powershell.AddScript({ + param($Query, $Variables, $Token) + $env:GITHUB_TOKEN = $Token + $body = @{ 'query' = $Query } + if ($Variables) { $body['variables'] = $Variables } + + $parameters = @{ + 'Headers' = @{ 'Authorization' = "Bearer $Token" } + 'Method' = 'Post' + 'Uri' = 'https://api.github.com/graphql' + 'Body' = (ConvertTo-Json $body -Depth 10) + 'ContentType' = 'application/json' + } + + try { + $response = Invoke-WebRequest @parameters + $env:GH_REQUEST_COUNTER = ([int] $env:GH_REQUEST_COUNTER) + 1 + return @{ Success = $true; Data = $response } + } catch { + return @{ Success = $false; Error = $_.Exception.Message } + } + }).AddArgument($q.Query).AddArgument($q.Variables).AddArgument($env:GITHUB_TOKEN) > $null + + $jobs += @{ + PowerShell = $powershell + AsyncResult = $powershell.BeginInvoke() + Query = $q + } + } + + foreach ($job in $jobs) { + try { + $result = $job.PowerShell.EndInvoke($job.AsyncResult) + if ($result.Success) { + $results += $result.Data + } else { + Write-Log "Parallel query failed: $($result.Error)" + $errors += @{ Query = $job.Query; Error = $result.Error } + } + } finally { + $job.PowerShell.Dispose() + } + } + + $runspacePool.Close() + $runspacePool.Dispose() + + if ($errors.Count -gt 0 -and $UseFallback) { + Write-Log "Some GraphQL queries failed, falling back to REST API" + return @{ Results = $results; Errors = $errors; FallbackUsed = $true } + } + + return @{ Results = $results; Errors = $errors; FallbackUsed = $false } +} + + function Invoke-GithubRequest { <# .SYNOPSIS @@ -313,5 +497,5 @@ function Get-LogURL { return $logURL } -Export-ModuleMember -Function Invoke-GithubRequest, Add-Comment, Get-AllChangedFilesInPR, New-Issue, Close-Issue, ` +Export-ModuleMember -Function Invoke-GithubRequest, Invoke-GithubGraphQL, Invoke-GithubGraphQLParallel, Add-Comment, Get-AllChangedFilesInPR, New-Issue, Close-Issue, ` Add-Label, Remove-Label, Get-RateLimit, Get-JobID, Get-LogURL From 1328263d70075066dd5257f0ee99d2fe4b228be3 Mon Sep 17 00:00:00 2001 From: MiyakoMeow <110924386+MiyakoMeow@users.noreply.github.com> Date: Tue, 3 Mar 2026 20:59:45 +0800 Subject: [PATCH 2/7] fix: issues --- src/Action/Issue.psm1 | 41 +++-------------------------------------- src/Github.psm1 | 8 +++++--- 2 files changed, 8 insertions(+), 41 deletions(-) diff --git a/src/Action/Issue.psm1 b/src/Action/Issue.psm1 index 13f5ce6..1d90b49 100644 --- a/src/Action/Issue.psm1 +++ b/src/Action/Issue.psm1 @@ -1,43 +1,8 @@ Join-Path $PSScriptRoot '..\Helpers.psm1' | Import-Module +Join-Path $PSScriptRoot '..\Github.psm1' | Import-Module Join-Path $PSScriptRoot 'Issue' | Get-ChildItem -Filter '*.psm1' | Select-Object -ExpandProperty Fullname | Import-Module -function Invoke-GithubGraphQLQuery { - <# - .SYNOPSIS - Execute a GraphQL query to GitHub API. - .PARAMETER Query - GraphQL query string. - .PARAMETER Variables - Hashtable of variables for the query. - #> - param( - [Parameter(Mandatory)] - [String] $Query, - [Hashtable] $Variables - ) - - $graphqlUrl = 'https://api.github.com/graphql' - $body = @{ 'query' = $Query } - if ($Variables) { $body['variables'] = $Variables } - - $parameters = @{ - 'Headers' = @{ - 'Authorization' = "Bearer $env:GITHUB_TOKEN" - 'Accept' = 'application/json' - } - 'Method' = 'Post' - 'Uri' = $graphqlUrl - 'Body' = (ConvertTo-Json $body -Depth 10) - 'ContentType' = 'application/json' - } - - Write-Log 'GraphQL Request' $parameters.Uri - $response = Invoke-WebRequest @parameters - $env:GH_REQUEST_COUNTER = ([int] $env:GH_REQUEST_COUNTER) + 1 - - return $response -} function Test-Hash { param ( @@ -128,7 +93,7 @@ function Test-Hash { try { Write-Log 'Attempting GraphQL query for repository and PRs...' - $response = Invoke-GithubGraphQLQuery -Query $graphqlQuery -Variables @{ + $response = Invoke-GithubGraphQL -Query $graphqlQuery -Variables @{ owner = $owner repo = $repo } @@ -145,7 +110,7 @@ function Test-Hash { Write-Log "GraphQL query failed, falling back to REST API: $($_.Exception.Message)" # Fallback to REST API $masterBranch = ((Invoke-GithubRequest "repos/$REPOSITORY").Content | ConvertFrom-Json).default_branch - $prs = (Invoke-GithubRequest "repos/$REPOSITORY/pulls?state=open&base=$masterBranch&sorting=updated").Content | ConvertFrom-Json + $prs = (Invoke-GithubRequest "repos/$REPOSITORY/pulls?state=open&base=$masterBranch&sort=updated").Content | ConvertFrom-Json } $message = @('You are right. Thank you for reporting.') diff --git a/src/Github.psm1 b/src/Github.psm1 index 236b7c3..5b3dc5b 100644 --- a/src/Github.psm1 +++ b/src/Github.psm1 @@ -19,7 +19,6 @@ function Invoke-GithubGraphQL { [Parameter(Mandatory, ValueFromPipeline)] [String] $Query, [Hashtable] $Variables, - [Switch] $UseFallback, [Int] $MaxRetries = 3 ) @@ -144,7 +143,7 @@ function Invoke-GithubGraphQLParallel { try { $response = Invoke-WebRequest @parameters - $env:GH_REQUEST_COUNTER = ([int] $env:GH_REQUEST_COUNTER) + 1 + return @{ Success = $true; Data = $response } return @{ Success = $true; Data = $response } } catch { return @{ Success = $false; Error = $_.Exception.Message } @@ -172,6 +171,9 @@ function Invoke-GithubGraphQLParallel { } } + # Update parent process counter after all runspaces complete + $env:GH_REQUEST_COUNTER = ([int]$env:GH_REQUEST_COUNTER) + $results.Count + $runspacePool.Close() $runspacePool.Dispose() @@ -497,5 +499,5 @@ function Get-LogURL { return $logURL } -Export-ModuleMember -Function Invoke-GithubRequest, Invoke-GithubGraphQL, Invoke-GithubGraphQLParallel, Add-Comment, Get-AllChangedFilesInPR, New-Issue, Close-Issue, ` +Export-ModuleMember -Function Invoke-GithubRequest, Invoke-GithubGraphQL, Invoke-GithubGraphQLParallel, Add-Comment, Get-AllChangedFilesInPR, New-Issue, Close-Issue, ` Add-Label, Remove-Label, Get-RateLimit, Get-JobID, Get-LogURL From 5fd664c29d02e268b5cb91c4b1049021621e1f82 Mon Sep 17 00:00:00 2001 From: MiyakoMeow <110924386+MiyakoMeow@users.noreply.github.com> Date: Tue, 3 Mar 2026 21:19:09 +0800 Subject: [PATCH 3/7] fix: issues, x2 --- src/Action/Issue.psm1 | 7 ++++--- src/Github.psm1 | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Action/Issue.psm1 b/src/Action/Issue.psm1 index 1d90b49..6c5f03e 100644 --- a/src/Action/Issue.psm1 +++ b/src/Action/Issue.psm1 @@ -79,8 +79,8 @@ function Test-Hash { number title body + baseRefName } - } } rateLimit { remaining @@ -116,7 +116,7 @@ function Test-Hash { $message = @('You are right. Thank you for reporting.') # TODO: Post labels at the end of function Add-Label -ID $IssueID -Label 'verified', 'hash-fix-needed' - $prs = $prs | Where-Object { $_.title -eq $titleToBePosted } + $prs = $prs | Where-Object { $_.title -eq $titleToBePosted -and $_.baseRefName -eq $masterBranch } # There is alreay PR for if ($prs.Count -gt 0) { @@ -140,7 +140,8 @@ function Test-Hash { try { $isProtected = ((Invoke-GithubRequest "repos/$REPOSITORY/branches/$masterBranch").Content | ConvertFrom-Json).protected } catch { - Write-Log "Failed to check branch protection status: $($_.Exception.Message)" + Write-Log "Failed to check branch protection status: $($_.Exception.Message). Assuming branch is protected for safety." + $isProtected = $true $isProtected = $false } diff --git a/src/Github.psm1 b/src/Github.psm1 index 5b3dc5b..d9813b6 100644 --- a/src/Github.psm1 +++ b/src/Github.psm1 @@ -143,7 +143,10 @@ function Invoke-GithubGraphQLParallel { try { $response = Invoke-WebRequest @parameters - return @{ Success = $true; Data = $response } + $payload = $response.Content | ConvertFrom-Json + if ($payload.errors) { + return @{ Success = $false; Error = ($payload.errors | ConvertTo-Json -Depth 10) } + } return @{ Success = $true; Data = $response } } catch { return @{ Success = $false; Error = $_.Exception.Message } From 5d863a56c84a59bbc14fc5e0757085750523ee03 Mon Sep 17 00:00:00 2001 From: MiyakoMeow <110924386+MiyakoMeow@users.noreply.github.com> Date: Tue, 3 Mar 2026 21:31:14 +0800 Subject: [PATCH 4/7] fix: issues, x3 --- src/Action/Issue.psm1 | 1 + src/Github.psm1 | 37 +++++++++++++++++++++++++------------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/Action/Issue.psm1 b/src/Action/Issue.psm1 index 6c5f03e..4d2015b 100644 --- a/src/Action/Issue.psm1 +++ b/src/Action/Issue.psm1 @@ -81,6 +81,7 @@ function Test-Hash { body baseRefName } + } } rateLimit { remaining diff --git a/src/Github.psm1 b/src/Github.psm1 index d9813b6..ae65b16 100644 --- a/src/Github.psm1 +++ b/src/Github.psm1 @@ -3,20 +3,18 @@ Join-Path $PSScriptRoot 'Helpers.psm1' | Import-Module function Invoke-GithubGraphQL { <# .SYNOPSIS - Invoke authenticated GitHub GraphQL API request with parallel query support and fallback. + Invoke authenticated GitHub GraphQL API request with retry logic. .PARAMETER Query GraphQL query string. .PARAMETER Variables Hashtable of variables for the GraphQL query. - .PARAMETER UseFallback - If set, falls back to REST API on GraphQL failure. .PARAMETER MaxRetries Maximum number of retry attempts on rate limit. Default is 3. .EXAMPLE Invoke-GithubGraphQL -Query 'query { viewer { login } }' #> param( - [Parameter(Mandatory, ValueFromPipeline)] + [Parameter(Mandatory)] [String] $Query, [Hashtable] $Variables, [Int] $MaxRetries = 3 @@ -102,8 +100,6 @@ function Invoke-GithubGraphQLParallel { Execute multiple GraphQL queries in parallel to avoid rate limits. .PARAMETER Queries Array of hashtables containing Query and Variables. - .PARAMETER UseFallback - If set, falls back to REST API on GraphQL failure. .EXAMPLE $queries = @( @{ Query = 'query($owner:String!, $name:String!) { repository(owner:$owner, name:$name) { defaultBranch } }'; Variables = @{ owner = 'octocat'; name = 'Hello-World' } } @@ -111,14 +107,32 @@ function Invoke-GithubGraphQLParallel { Invoke-GithubGraphQLParallel -Queries $queries #> param( - [Parameter(Mandatory)] - [Hashtable[]] $Queries, - [Switch] $UseFallback + [AllowEmptyCollection()] + [Hashtable[]] $Queries ) $results = @() $errors = @() + # Early return for empty or null queries + if ($null -eq $Queries -or $Queries.Count -eq 0) { + return @{ Results = @(); Errors = @(); FallbackUsed = $false } + } + + $results = @() + $errors = @() + + # Early return for empty queries + if ($Queries.Count -eq 0) { + return @{ Results = @(); Errors = @(); FallbackUsed = $false } + } + + # Use Runspaces for parallel execution + $runspacePool = [runspacefactory]::CreateRunspacePool(1, [Math]::Min(5, $Queries.Count)) + + $results = @() + $errors = @() + # Use Runspaces for parallel execution $runspacePool = [runspacefactory]::CreateRunspacePool(1, [Math]::Min(5, $Queries.Count)) $runspacePool.Open() @@ -180,9 +194,8 @@ function Invoke-GithubGraphQLParallel { $runspacePool.Close() $runspacePool.Dispose() - if ($errors.Count -gt 0 -and $UseFallback) { - Write-Log "Some GraphQL queries failed, falling back to REST API" - return @{ Results = $results; Errors = $errors; FallbackUsed = $true } + if ($errors.Count -gt 0) { + Write-Log "Some GraphQL queries failed with errors: $($errors.Count)" } return @{ Results = $results; Errors = $errors; FallbackUsed = $false } From 9afb768d0f76ececa9a88f12970e14d37ad3b60c Mon Sep 17 00:00:00 2001 From: MiyakoMeow <110924386+MiyakoMeow@users.noreply.github.com> Date: Tue, 3 Mar 2026 23:34:06 +0800 Subject: [PATCH 5/7] fix: issues, x4 --- src/Action/Issue.psm1 | 1 - src/Github.psm1 | 20 +++----------------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/src/Action/Issue.psm1 b/src/Action/Issue.psm1 index 4d2015b..eca9cb5 100644 --- a/src/Action/Issue.psm1 +++ b/src/Action/Issue.psm1 @@ -143,7 +143,6 @@ function Test-Hash { } catch { Write-Log "Failed to check branch protection status: $($_.Exception.Message). Assuming branch is protected for safety." $isProtected = $true - $isProtected = $false } if ($isProtected) { diff --git a/src/Github.psm1 b/src/Github.psm1 index ae65b16..7d6ad56 100644 --- a/src/Github.psm1 +++ b/src/Github.psm1 @@ -111,9 +111,6 @@ function Invoke-GithubGraphQLParallel { [Hashtable[]] $Queries ) - $results = @() - $errors = @() - # Early return for empty or null queries if ($null -eq $Queries -or $Queries.Count -eq 0) { return @{ Results = @(); Errors = @(); FallbackUsed = $false } @@ -121,19 +118,6 @@ function Invoke-GithubGraphQLParallel { $results = @() $errors = @() - - # Early return for empty queries - if ($Queries.Count -eq 0) { - return @{ Results = @(); Errors = @(); FallbackUsed = $false } - } - - # Use Runspaces for parallel execution - $runspacePool = [runspacefactory]::CreateRunspacePool(1, [Math]::Min(5, $Queries.Count)) - - $results = @() - $errors = @() - - # Use Runspaces for parallel execution $runspacePool = [runspacefactory]::CreateRunspacePool(1, [Math]::Min(5, $Queries.Count)) $runspacePool.Open() @@ -174,11 +158,13 @@ function Invoke-GithubGraphQLParallel { } } + $successfulCount = 0 foreach ($job in $jobs) { try { $result = $job.PowerShell.EndInvoke($job.AsyncResult) if ($result.Success) { $results += $result.Data + $successfulCount++ } else { Write-Log "Parallel query failed: $($result.Error)" $errors += @{ Query = $job.Query; Error = $result.Error } @@ -189,7 +175,7 @@ function Invoke-GithubGraphQLParallel { } # Update parent process counter after all runspaces complete - $env:GH_REQUEST_COUNTER = ([int]$env:GH_REQUEST_COUNTER) + $results.Count + $env:GH_REQUEST_COUNTER = ([int]$env:GH_REQUEST_COUNTER) + $successfulCount $runspacePool.Close() $runspacePool.Dispose() From bf534d7b2f093512944ee33d913c5c6a5af1c527 Mon Sep 17 00:00:00 2001 From: MiyakoMeow <110924386+MiyakoMeow@users.noreply.github.com> Date: Wed, 4 Mar 2026 02:09:50 +0800 Subject: [PATCH 6/7] fix: issues, x5 --- src/Action/Issue.psm1 | 9 ++++++++- src/Github.psm1 | 35 +++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/Action/Issue.psm1 b/src/Action/Issue.psm1 index eca9cb5..a9c4e73 100644 --- a/src/Action/Issue.psm1 +++ b/src/Action/Issue.psm1 @@ -114,7 +114,14 @@ function Test-Hash { $prs = (Invoke-GithubRequest "repos/$REPOSITORY/pulls?state=open&base=$masterBranch&sort=updated").Content | ConvertFrom-Json } - $message = @('You are right. Thank you for reporting.') +$message = @('You are right. Thank you for reporting.') + # TODO: Post labels at the end of function + Add-Label -ID $IssueID -Label 'verified', 'hash-fix-needed' + $titleToBePosted = "$manifestNameAsInBucket@$($man.version): Fix hash" + $prs = $prs | Where-Object { + $_.title -eq $titleToBePosted -and + (($_.baseRefName -eq $masterBranch) -or ($_.base.ref -eq $masterBranch)) + } # TODO: Post labels at the end of function Add-Label -ID $IssueID -Label 'verified', 'hash-fix-needed' $prs = $prs | Where-Object { $_.title -eq $titleToBePosted -and $_.baseRefName -eq $masterBranch } diff --git a/src/Github.psm1 b/src/Github.psm1 index 7d6ad56..9a8f520 100644 --- a/src/Github.psm1 +++ b/src/Github.psm1 @@ -159,26 +159,29 @@ function Invoke-GithubGraphQLParallel { } $successfulCount = 0 - foreach ($job in $jobs) { - try { - $result = $job.PowerShell.EndInvoke($job.AsyncResult) - if ($result.Success) { - $results += $result.Data - $successfulCount++ - } else { - Write-Log "Parallel query failed: $($result.Error)" - $errors += @{ Query = $job.Query; Error = $result.Error } + try { + foreach ($job in $jobs) { + try { + $result = $job.PowerShell.EndInvoke($job.AsyncResult) + if ($result.Success) { + $results += $result.Data + $successfulCount++ + } else { + Write-Log "Parallel query failed: $($result.Error)" + $errors += @{ Query = $job.Query; Error = $result.Error } + } + } finally { + $job.PowerShell.Dispose() } - } finally { - $job.PowerShell.Dispose() } - } - # Update parent process counter after all runspaces complete - $env:GH_REQUEST_COUNTER = ([int]$env:GH_REQUEST_COUNTER) + $successfulCount + # Update parent process counter after all runspaces complete + $env:GH_REQUEST_COUNTER = ([int]$env:GH_REQUEST_COUNTER) + $successfulCount + } finally { + $runspacePool.Close() + $runspacePool.Dispose() + } - $runspacePool.Close() - $runspacePool.Dispose() if ($errors.Count -gt 0) { Write-Log "Some GraphQL queries failed with errors: $($errors.Count)" From f642dd7b5a03bc6518b7cadb233b9173ac1f5f74 Mon Sep 17 00:00:00 2001 From: MiyakoMeow <110924386+MiyakoMeow@users.noreply.github.com> Date: Wed, 4 Mar 2026 02:26:05 +0800 Subject: [PATCH 7/7] fix: issues, x6 --- src/Action/Issue.psm1 | 4 +--- src/Github.psm1 | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Action/Issue.psm1 b/src/Action/Issue.psm1 index a9c4e73..781b065 100644 --- a/src/Action/Issue.psm1 +++ b/src/Action/Issue.psm1 @@ -122,9 +122,7 @@ $message = @('You are right. Thank you for reporting.') $_.title -eq $titleToBePosted -and (($_.baseRefName -eq $masterBranch) -or ($_.base.ref -eq $masterBranch)) } - # TODO: Post labels at the end of function - Add-Label -ID $IssueID -Label 'verified', 'hash-fix-needed' - $prs = $prs | Where-Object { $_.title -eq $titleToBePosted -and $_.baseRefName -eq $masterBranch } + # There is alreay PR for if ($prs.Count -gt 0) { diff --git a/src/Github.psm1 b/src/Github.psm1 index 9a8f520..61e5317 100644 --- a/src/Github.psm1 +++ b/src/Github.psm1 @@ -205,7 +205,7 @@ function Invoke-GithubRequest { Invoke-GithubRequest 'repos/User/Repo/pulls' -Method 'Post' -Body @{ 'body' = 'body' } #> param( - [Parameter(Mandatory, ValueFromPipeline)] + [Parameter(Mandatory)] [String] $Query, [Microsoft.PowerShell.Commands.WebRequestMethod] $Method = 'Get', [Hashtable] $Body