Skip to content

Commit

Permalink
fix(checkver): Monkey patch to prevent github rate limit hits (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash258 committed Apr 10, 2021
1 parent 1785b66 commit f870c47
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
19 changes: 11 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
- **checkup**: Test Windows Defender exlusions only when executed with administrator privileges
- Remove automatic config migration
- **config**: Do not support `rootPath`, `globalPath`, `cachePath` config options
- **checkver**: Properly reflect execution issues with exit code
- **checkver**:
- Prevent hitting GitHub rate limits
- GitHub checkver will use `api.github.com/repos` and github token from environment `GITHUB_TOKEN` or config option `githubToken`
- Properly reflect execution issues with exit code

### 0.6-pre2

Expand Down Expand Up @@ -51,9 +54,9 @@
- **binaries**: Support YAML typed manifests
- General code cleanup and documentation tweaks

## [0.55](https://github.com/Ash258/Scoop-Core/milestone/2)
## [0.5.5](https://github.com/Ash258/Scoop-Core/milestone/2)

### 0.55-pre5
### 0.5.5-pre5

- **manifests**: Introduce manifest helpers to avoid repeating lines in manifests
- `Assert-Administrator`, `Assert-WindowsMinimalVersion`, `Assert-ScoopConfigValue`, `Test-Persistence`, `Edit-File`, `Remove-AppDirItem`, `New-JavaShortcutWrapper`
Expand All @@ -76,31 +79,31 @@
- **autoupdate**: Support base64 for all extraction types
- Small code cleanup and refactorings

### 0.55-pre4
### 0.5.5-pre4

- **update**: Ignore merge commits in update log
- `scoop --version` reports PowerShell version
- **depends**: Correctly detect globally installed dependencies
- **buckets**: Indicate successfull bucket removal
- **buckets**: Indicate inability of bucket removal

### 0.55-pre3
### 0.5.5-pre3

- Sync with upstream/master

### 0.55-pre2
### 0.5.5-pre2

- `scoop search` reimplemented
- **scoop-config**: Fix regression from `--help` addition
- **decompress**: Fix 7zip requirements detection
- **autoupdate**: Added `$headVersion` and `$tailVersion` substitutes

### 0.55.1-pre
### 0.5.5-pre1

- Allow `-h` and `--help` parameters for all scoop commands
- Lots of refactorings

### 0.55-pre - Abort deprecation 🎉
### 0.5.5-pre - Abort deprecation 🎉

- `abort` funcion completely eliminated
- Multiple manifest installation is not broken in case of one failure. (for example)
Expand Down
16 changes: 14 additions & 2 deletions bin/checkver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ $Search = $App
$Queue = @()
$UNIVERSAL_REGEX = '[vV]?([\d.]+)'
$GITHUB_REGEX = "/releases/tag/$UNIVERSAL_REGEX"
$GH_TOKEN = $env:GITHUB_TOKEN
$cfToken = get_config 'githubToken'
if ($cfToken) { $GH_TOKEN = $cfToken }
$exitCode = 0
$problems = 0

Expand Down Expand Up @@ -270,6 +273,7 @@ foreach ($q in $Queue) {
$xpath = ''
$replace = ''
$reverse = $json.checkver.reverse -and $json.checkver.reverse -eq 'true'
$useGithubAPI = $false

if ($json.checkver.url) { $url = $json.checkver.url }

Expand All @@ -278,12 +282,15 @@ foreach ($q in $Queue) {
Write-UserMessage -Message "$name checkver expects the homepage to be a github repository" -Err
$problemOccured = $true
}
$url = $json.homepage + '/releases/latest'
$url = $json.homepage.TrimEnd('/') + '/releases/latest'
$regex = $GITHUB_REGEX
$useGithubAPI = $true
}
if ($json.checkver.github) {
$url = $json.checkver.github + '/releases/latest'
$url = $json.checkver.github.TrimEnd('/') + '/releases/latest'
$regex = $GITHUB_REGEX
# TODO: See if this could be used allways
if ($json.checkver.PSObject.Properties.Count -eq 1) { $useGithubAPI = $true }
}

if ($json.checkver.re) {
Expand All @@ -305,6 +312,11 @@ foreach ($q in $Queue) {
$regex = if ($json.checkver -is [System.String]) { $json.checkver } else { $UNIVERSAL_REGEX }
}

if ($url -like '*api.github.com/*') { $useGithubAPI = $true }
if ($useGithubAPI -and ($null -ne $GH_TOKEN)) {
$url = $url -replace '//(www\.)?github.com/', '//api.github.com/repos/'
$wc.Headers.Add('Authorization', "token $GH_TOKEN")
}
$url = Invoke-VariableSubstitution -Entity $url -Substitutes $substitutions

$state = New-Object PSObject @{
Expand Down
3 changes: 2 additions & 1 deletion supporting/completion/scoop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ local configOptions = parser({
'SCOOP_BRANCH',
'show_update_log' .. booleanParser,
'virustotal_api_key',
'proxy'
'proxy',
'githubToken'
})

-- region Functions
Expand Down

0 comments on commit f870c47

Please sign in to comment.