Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scoop-search): Remove redundant 'bucket/' in search result #4773

Merged
merged 4 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- **scoop-bucket:** Fix date formatting issues with git bucket(s) ([#4759](https://github.com/ScoopInstaller/Scoop/issues/4759))
- **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