Skip to content

Commit

Permalink
fix(scoop-search): Remove redundant 'bucket/' in search result (Scoop…
Browse files Browse the repository at this point in the history
…Installer#4773)

* fix remote search

* add hint

* tweak

* docs(changelog): Update CHANGELOG

Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com>
  • Loading branch information
zStruCat and niheaven authored Mar 7, 2022
1 parent 63b858c commit 43d5e99
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- **scoop-alias:** Fix alias initialization ([#4737](https://github.com/ScoopInstaller/Scoop/issues/4737))
- **scoop-checkup:** Skip 'check_windows_defender' when have not admin privileges ([#4699](https://github.com/ScoopInstaller/Scoop/issues/4699))
- **scoop-cleanup:** Remove apps other than current version ([#4665](https://github.com/ScoopInstaller/Scoop/issues/4665))
- **scoop-search:** Remove redundant 'bucket/' in search result ([#4773](https://github.com/ScoopInstaller/Scoop/issues/4773))
- **scoop-update:** Skip updating non git buckets ([#4670](https://github.com/ScoopInstaller/Scoop/issues/4670), [#4672](https://github.com/ScoopInstaller/Scoop/issues/4672))

### Performance Improvements
Expand Down
26 changes: 12 additions & 14 deletions libexec/scoop-search.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,26 @@ function search_bucket($bucket, $query) {
}

function download_json($url) {
$progressPreference = 'silentlycontinue'
$result = invoke-webrequest $url -UseBasicParsing | Select-Object -exp content | convertfrom-json
$progressPreference = 'continue'
$ProgressPreference = 'SilentlyContinue'
$result = Invoke-WebRequest $url -UseBasicParsing | Select-Object -ExpandProperty content | ConvertFrom-Json
$ProgressPreference = 'Continue'
$result
}

function github_ratelimit_reached {
$api_link = "https://api.github.com/rate_limit"
$api_link = 'https://api.github.com/rate_limit'
(download_json $api_link).rate.remaining -eq 0
}

function search_remote($bucket, $query) {
$repo = known_bucket_repo $bucket

$uri = [system.uri]($repo)
if ($uri.absolutepath -match '/([a-zA-Z0-9]*)/([a-zA-Z0-9-]*)(.git|/)?') {
$user = $matches[1]
$repo_name = $matches[2]
$uri = [System.Uri](known_bucket_repo $bucket)
if ($uri.AbsolutePath -match '/([a-zA-Z0-9]*)/([a-zA-Z0-9-]*)(?:.git|/)?') {
$user = $Matches[1]
$repo_name = $Matches[2]
$api_link = "https://api.github.com/repos/$user/$repo_name/git/trees/HEAD?recursive=1"
$result = download_json $api_link | Select-Object -exp tree | Where-Object {
$_.path -match "(^(.*$query.*).json$)"
} | ForEach-Object { $matches[2] }
$result = download_json $api_link | Select-Object -ExpandProperty tree |
Where-Object -Value "^(?:bucket/)?(.*$query.*)\.json$" -Property Path -Match |
ForEach-Object { $Matches[1] }
}

$result
Expand All @@ -90,7 +88,7 @@ function search_remotes($query) {
}

$results | ForEach-Object {
"'$($_.bucket)' bucket:"
"'$($_.bucket)' bucket (install using 'scoop install $($_.bucket)/<app>'):"
$_.results | ForEach-Object { " $_" }
""
}
Expand Down

0 comments on commit 43d5e99

Please sign in to comment.