Skip to content

Commit 727469f

Browse files
🩹 [Patch]: Refactor font data retrieval to use GitHub PowerShell (#42)
## Description This pull request updates the `scripts/Update-FontsData.ps1` script to improve the retrieval of font data from the Nerd Fonts repository. The changes replace the use of `Invoke-RestMethod` with a more structured approach using custom PowerShell functions, enhancing readability and maintainability. Enhancements to font data retrieval: * Replaced low-level commands with GitHub PowerShell commands: * `Invoke-RestMethod` with `Get-GitHubRelease` to fetch the latest release data from the Nerd Fonts repository. * `browser_download_url` property under assets on a release, with `Get-GitHubReleaseAsset` to fetch the URL of the assets that are added to the release. * Updated the loop to use `[PSCustomObject]` instead of `[ordered]@` for better view and troubleshooting. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --------- Co-authored-by: Copilot <[email protected]>
1 parent 920af2d commit 727469f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

scripts/Update-FontsData.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ $branchName = "auto-font-update-$timeStamp"
1111
git checkout -b $branchName
1212

1313
# 4. Retrieve the latest font data from Nerd Fonts.
14-
$release = Invoke-RestMethod 'https://api.github.com/repos/ryanoasis/nerd-fonts/releases/latest'
14+
$release = Get-GitHubRelease -Owner ryanoasis -Repository nerd-fonts
1515
$fonts = @()
16-
$fontArchives = $release.assets.browser_download_url | Where-Object { $_ -like '*.zip' }
16+
$fontAssets = $release | Get-GitHubReleaseAsset | Where-Object { $_.Name -like '*.zip' }
1717

18-
foreach ($fontArchive in $fontArchives) {
19-
$fonts += [ordered]@{
20-
Name = $fontArchive.Split('/')[-1].Split('.')[0]
21-
URL = $fontArchive
18+
foreach ($fontArchive in $fontAssets) {
19+
$fonts += [PSCustomObject]@{
20+
Name = $fontArchive.Name.Split('.')[0]
21+
URL = $fontArchive.Url
2222
}
2323
}
2424

0 commit comments

Comments
 (0)