Skip to content

Commit e3de578

Browse files
⚙️ [Maintenance]: Fix Update-FontsData script: gh CLI json args and hardcoded repo name (#152)
The Update-FontsData workflow script now correctly passes arguments to the `gh` CLI and uses the `GITHUB_REPOSITORY` environment variable instead of a hardcoded repository name, making the script portable and fixing the workflow failure. - Fixes #151 ## Fix `--json` argument parsing The `--json number, title` argument was split by PowerShell into two separate arguments (`number,` and `title`), causing `gh` CLI to report `Unknown JSON field: "number title"`. The argument is now quoted as `'number,title'` to ensure it is passed as a single value. ## Replace hardcoded repository name with variable All four occurrences of the hardcoded `'PSModule/GoogleFonts'` repo name in `gh` CLI calls have been replaced with a `$repoName` variable, set from `$env:GITHUB_REPOSITORY`. This makes the script work correctly in any fork or renamed repository without code changes. ## Fix `gh` CLI typo A typo in the PR close command (`Run h pr close` instead of `Run gh pr close`) has been corrected.
1 parent 57437c4 commit e3de578

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

scripts/Update-FontsData.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
}
3434
}
3535

36+
$repoName = $env:GITHUB_REPOSITORY
37+
3638
Install-PSResource -Repository PSGallery -TrustRepository -Name 'Json'
3739

3840
Connect-GitHubApp -Organization 'PSModule' -Default
@@ -143,7 +145,7 @@ LogGroup 'Process changes' {
143145
if ($retryCount -gt 0) {
144146
Start-Sleep -Seconds $retryDelays[$retryCount - 1]
145147
}
146-
$newPRJson = Run gh pr list --repo 'PSModule/GoogleFonts' --head $targetBranch --state open --json number, title --limit 1
148+
$newPRJson = Run gh pr list --repo $repoName --head $targetBranch --state open --json 'number,title' --limit 1
147149
$newPR = $newPRJson | ConvertFrom-Json | Select-Object -First 1
148150
if ($null -eq $newPR -or $null -eq $newPR.number) {
149151
$newPR = $null
@@ -159,7 +161,7 @@ LogGroup 'Process changes' {
159161
Write-Output "Found new PR #$($newPR.number): $($newPR.title)"
160162

161163
# Find existing open Auto-Update PRs (excluding the one we just created)
162-
$existingPRsJson = Run gh pr list --repo 'PSModule/GoogleFonts' --state open --search 'Auto-Update in:title' --json number, title
164+
$existingPRsJson = Run gh pr list --repo $repoName --state open --search 'Auto-Update in:title' --json 'number,title'
163165
$existingPRs = $existingPRsJson | ConvertFrom-Json | Where-Object { $_.number -ne $newPR.number }
164166

165167
if ($existingPRs) {
@@ -173,10 +175,10 @@ This PR has been superseded by #$($newPR.number) and will be closed automaticall
173175
174176
The font data has been updated in the newer PR. Please refer to #$($newPR.number) for the most current changes.
175177
"@
176-
Run gh pr comment $pr.number --repo 'PSModule/GoogleFonts' --body $comment
178+
Run gh pr comment $pr.number --repo $repoName --body $comment
177179

178180
# Close the PR
179-
Run h pr close $pr.number --repo 'PSModule/GoogleFonts'
181+
Run gh pr close $pr.number --repo $repoName
180182

181183
Write-Output "Successfully closed PR #$($pr.number)"
182184
}

0 commit comments

Comments
 (0)