Skip to content

feat(config): Try SCOOP_GH_TOKEN value first before gh_token value from config #4842

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

Merged
merged 1 commit into from Mar 26, 2022
Merged
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
feat(config): try SCOOP_GH_TOKEN value first before gh_token value fr…
…om config
  • Loading branch information
Alex Stelmachonak committed Mar 25, 2022
commit 186a360244d8e4b0a7e33b28ef2b97ee2749efed
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
### Features

- **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

@@ -20,6 +19,8 @@
- **bucket:** Move 'Find-Manifest' and 'list_buckets' to 'buckets' ([#4814](https://github.com/ScoopInstaller/Scoop/issues/4814))
- **relpath:** Use `$PSScriptRoot` instead of `relpath` ([#4793](https://github.com/ScoopInstaller/Scoop/issues/4793))
- **reset_aliases:** Move core function of `reset_aliases` to `scoop` ([#4794](https://github.com/ScoopInstaller/Scoop/issues/4794))
- **config:** Rename checkver_token to gh_token and SCOOP_CHECKVER_TOKEN to SCOOP_GH_TOKEN ([#4832](https://github.com/ScoopInstaller/Scoop/pull/4832))
- **config:** try SCOOP_GH_TOKEN value first before gh_token value from config ([#4842](https://github.com/ScoopInstaller/Scoop/pull/4842))

### Documentation

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

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

# don't use $Version with $App = '*'
if ($App -eq '*' -and $Version -ne '') {
6 changes: 5 additions & 1 deletion lib/core.ps1
Original file line number Diff line number Diff line change
@@ -1005,6 +1005,10 @@ function get_hash([String] $multihash) {
return $type, $hash.ToLower()
}

function Get-GitHubToken {
return $env:SCOOP_GH_TOKEN, (get_config 'gh_token') | Where-Object -Property Length -Value 0 -GT | Select-Object -First 1
}

function handle_special_urls($url)
{
# FossHub.com
@@ -1032,7 +1036,7 @@ function handle_special_urls($url)
}

# Github.com
if ($url -match 'github.com/(?<owner>[^/]+)/(?<repo>[^/]+)/releases/download/(?<tag>[^/]+)/(?<file>[^/#]+)(?<filename>.*)' -and ($token = get_config 'gh_token')) {
if ($url -match 'github.com/(?<owner>[^/]+)/(?<repo>[^/]+)/releases/download/(?<tag>[^/]+)/(?<file>[^/#]+)(?<filename>.*)' -and ($token = Get-GitHubToken)) {
$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)"
3 changes: 2 additions & 1 deletion lib/install.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
. "$PSScriptRoot\core.ps1"
. "$PSScriptRoot\autoupdate.ps1"
. "$PSScriptRoot\buckets.ps1"

@@ -364,7 +365,7 @@ function dl($url, $to, $cookies, $progress) {
}
if ($url -match 'api\.github\.com/repos') {
$wreq.Accept = 'application/octet-stream'
$wreq.Headers['Authorization'] = "token $(get_config 'gh_token')"
$wreq.Headers['Authorization'] = "token $(Get-GitHubToken)"
}
if ($cookies) {
$wreq.Headers.Add('Cookie', (cookie_header $cookies))