Skip to content

feat(download): try gh auth token for a github token - #6725

Merged
niheaven merged 4 commits into
ScoopInstaller:developfrom
refack:develop-gh-token
Nov 8, 2026
Merged

niheaven merged 4 commits into
ScoopInstaller:developfrom
refack:develop-gh-token

Conversation

@refack

@refack refack commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

Follow up for #6712 - set scoop config gh_token 'ask-gh' to get scoop to ask gh for a token (stored in Windows Credential Manager)

Motivation and Context

Relates to #6712

How Has This Been Tested?

  • unit tests
  • my live set-up

Checklist:

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge, with no new actionable issues found.

Summary

Adds gh auth token --hostname github.com as a fallback after configured and environment tokens.

  • GitHub requests can use a token from the signed-in CLI.

Reviews (7) · Last reviewed commit: "add chglog" · Reviewed by Greptile

Copilot AI lite review requested due to automatic review settings August 27, 2026 15:04
@coderabbitai

coderabbitai Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: c3ebc8e2-c78c-4153-b338-608de0af58d0

📥 Commits

Reviewing files that changed from the base of the PR and between 620465a and a124a46.

📒 Files selected for processing (1)
  • libexec/scoop-config.ps1
🚧 Files skipped from review as they are similar to previous changes (1)
  • libexec/scoop-config.ps1

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


Summary by CodeRabbit

  • Bug Fixes

    • Improved GitHub authentication handling when optional token sources are unset, including under strict error handling.
    • Preserved token precedence, CLI fallback, and per-session caching behavior.
  • Documentation

    • Expanded configuration guidance for retrieving credentials through the GitHub CLI and enabling Git history searches during installation.
  • Tests

    • Added coverage for token precedence, CLI fallback, caching, failure handling, and strict-mode behavior.

Walkthrough

Get-GitHubToken now initializes its CLI probe state and uses safe truthiness checks for token sources. The ask-gh and use_git_history configuration settings are documented. Tests cover precedence, caching, failures, and StrictMode behavior.

Changes

GitHub token resolution update

Layer / File(s) Summary
ask-gh token lookup flow
lib/download.ps1, libexec/scoop-config.ps1
Get-GitHubToken initializes CLI probe state before reading it and uses truthiness checks for unset token values. CLI fallback and caching remain guarded. Configuration help documents ask-gh and use_git_history.
Token resolution validation
test/Scoop-Download.Tests.ps1
Tests verify token precedence, ask-gh handling, single-process CLI probing, failure behavior, cache reset, and execution under StrictMode.

Merge Risk: 🟡 Moderate · up to a124a

The new GitHub token lookup can send credentials to non-HTTPS URLs or loosely matched hosts, which could expose tokens. This bounded security risk should be addressed or explicitly accepted before merging.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: using gh auth token to obtain a GitHub token.
Description check ✅ Passed The description directly explains the ask-gh configuration, token storage behavior, related issue, testing, and documentation updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.)


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in mechanism to retrieve a GitHub API token via the GitHub CLI (gh auth token) when scoop config gh_token is set to the sentinel value ask-gh, avoiding storing the token in Scoop’s config while still enabling authenticated GitHub requests (e.g., private repo downloads, rate-limit avoidance).

Changes:

  • Update Get-GitHubToken to treat ask-gh as a sentinel and, when configured, query gh auth token --hostname github.com once per process as a last resort.
  • Add Pester coverage validating precedence (env/config), sentinel behavior, CLI invocation conditions, and one-probe-per-process caching.
  • Document the new gh_token: ask-gh behavior in scoop-config help text.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
test/Scoop-Download.Tests.ps1 Adds unit tests covering ask-gh behavior, source precedence, and probe caching for Get-GitHubToken.
libexec/scoop-config.ps1 Documents the new gh_token = 'ask-gh' option and its requirements.
lib/download.ps1 Implements the ask-gh sentinel flow and a per-process cached gh auth token probe.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lib/download.ps1 (1)

601-614: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Sensitive Data Exposure (CWE-319): Cleartext Transmission of Sensitive Information

Reachability: External · Exploitability: Moderate

Restrict the CLI token to HTTPS requests for api.github.com.

When ask-gh returns a token, Invoke-Download can attach it to any URL containing api.github.com/repos. Parse the request URI and require https, the exact api.github.com host, and an /repos/ path before adding Authorization.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: dda0a3a0-6ca9-40d6-9657-54f5ef817f7e

📥 Commits

Reviewing files that changed from the base of the PR and between baf87f5 and 620465a.

📒 Files selected for processing (2)
  • lib/download.ps1
  • test/Scoop-Download.Tests.ps1

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@refack
refack marked this pull request as draft September 10, 2026 02:48
@refack
refack marked this pull request as ready for review September 10, 2026 02:54
@niheaven

niheaven commented Nov 2, 2026

Copy link
Copy Markdown
Member

Use gh as default (if gh-token is not set, try gh first), and move to Pester 6's test

@refack
refack force-pushed the develop-gh-token branch 2 times, most recently from 0d7bc91 to 4c04bde Compare November 7, 2026 16:50
Comment thread test/Scoop-Download.Tests.ps1 Resolved
@refack

refack commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Use gh as default (if gh-token is not set, try gh first), and move to Pester 6's test

We uncovered a bug: setting a scoop config $null or scoop config '' would fail all requests with 401 since scoop would add an empty value Authorization: Bearer HTTP header
I've documented this as the opt-out

@niheaven
niheaven merged commit 1155daa into ScoopInstaller:develop Nov 8, 2026
3 checks passed
@refack
refack deleted the develop-gh-token branch November 8, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants