Skip to content

Commit

Permalink
feat(config): Rename checkver_token to gh_token and SCOOP_CHECKVER_TO…
Browse files Browse the repository at this point in the history
…KEN to SCOOP_GH_TOKEN (ScoopInstaller#4832)

* Properly filtering null input in dl function when private_hosts is not set in config

* Rename checkver_token to gh_token and SCOOP_CHECKVER_TOKEN to SCOOP_GH_TOKEN
  • Loading branch information
Alex Stelmachonak authored Mar 21, 2022
1 parent 45db5fb commit ad3fc4f
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

### Features

- **install:** Allow downloading from private repositories ([$4254](https://github.com/ScoopInstaller/Scoop/issues/4243))
- **install:** Allow downloading from private repositories ([#4254](https://github.com/ScoopInstaller/Scoop/issues/4243))
- **config:** Rename checkver_token to gh_token and SCOOP_CHECKVER_TOKEN to SCOOP_GH_TOKEN ([#4832](https://github.com/ScoopInstaller/Scoop/pull/4832))

### Bug Fixes

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ $env:SCOOP_CACHE='F:\ScoopCache'
# run the installer
```

### Configure Scoop to use a GitHub API token during searching and checkver by setting `SCOOP_CHECKVER_TOKEN`
### Configure Scoop to use a GitHub API token during searching and checkver by setting `SCOOP_GH_TOKEN`

```powershell
$env:SCOOP_CHECKVER_TOKEN='<paste-token-here>'
[Environment]::SetEnvironmentVariable('SCOOP_CHECKVER_TOKEN', $env:SCOOP_CHECKVER_TOKEN, 'Machine')
$env:SCOOP_GH_TOKEN='<paste-token-here>'
[Environment]::SetEnvironmentVariable('SCOOP_GH_TOKEN', $env:SCOOP_GH_TOKEN, 'Machine')
# search for an app
```

Expand Down
2 changes: 1 addition & 1 deletion bin/checkver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ param(

$Dir = Resolve-Path $Dir
$Search = $App
$GitHubToken = $env:SCOOP_CHECKVER_TOKEN, (get_config 'checkver-token') | Where-Object -Property Length -Value 0 -GT | Select-Object -First 1
$GitHubToken = $env:SCOOP_GH_TOKEN, (get_config 'gh_token') | Where-Object -Property Length -Value 0 -GT | Select-Object -First 1

# don't use $Version with $App = '*'
if ($App -eq '*' -and $Version -ne '') {
Expand Down
2 changes: 1 addition & 1 deletion lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ function handle_special_urls($url)
}

# Github.com
if ($url -match 'github.com/(?<owner>[^/]+)/(?<repo>[^/]+)/releases/download/(?<tag>[^/]+)/(?<file>[^/#]+)(?<filename>.*)' -and ($token = get_config 'checkver_token')) {
if ($url -match 'github.com/(?<owner>[^/]+)/(?<repo>[^/]+)/releases/download/(?<tag>[^/]+)/(?<file>[^/#]+)(?<filename>.*)' -and ($token = get_config 'gh_token')) {
$headers = @{ "Authorization" = "token $token" }
$privateUrl = "https://api.github.com/repos/$($Matches.owner)/$($Matches.repo)"
$assetUrl = "https://api.github.com/repos/$($Matches.owner)/$($Matches.repo)/releases/tags/$($Matches.tag)"
Expand Down
4 changes: 2 additions & 2 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,13 @@ function dl($url, $to, $cookies, $progress) {
}
if ($url -match 'api\.github\.com/repos') {
$wreq.Accept = 'application/octet-stream'
$wreq.Headers['Authorization'] = "token $(get_config 'checkver_token')"
$wreq.Headers['Authorization'] = "token $(get_config 'gh_token')"
}
if ($cookies) {
$wreq.Headers.Add('Cookie', (cookie_header $cookies))
}

get_config 'private_hosts' | Where-Object { $url -match $_.match } | ForEach-Object {
get_config 'private_hosts' | Where-Object { $_ -ne $null -and $url -match $_.match } | ForEach-Object {
(ConvertFrom-StringData -StringData $_.Headers).GetEnumerator() | ForEach-Object {
$wreq.Headers[$_.Key] = $_.Value
}
Expand Down
2 changes: 1 addition & 1 deletion libexec/scoop-config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
# cachePath:
# For downloads, defaults to 'cache' folder under Scoop root directory.
#
# checkver_token:
# gh_token:
# GitHub API token used to make authenticated requests.
# This is essential for checkver and similar functions to run without
# incurring rate limits and download from private repositories.
Expand Down

0 comments on commit ad3fc4f

Please sign in to comment.