Skip to content

fix(github): allow GitHub client creation without a token for unauthenticated access#8054

Merged
olblak merged 3 commits intoupdatecli:mainfrom
railgun-0402:fix/github-allow-unauthenticated-client
Mar 22, 2026
Merged

fix(github): allow GitHub client creation without a token for unauthenticated access#8054
olblak merged 3 commits intoupdatecli:mainfrom
railgun-0402:fix/github-allow-unauthenticated-client

Conversation

@railgun-0402
Copy link
Copy Markdown
Contributor

Fix #7643

The test TestNew/No_Error_for_missing_token was failing locally because client.New() returned an error when no GitHub token was found, even though the test expected success.

Previously, when no token was found (neither from environment variables nor from configuration), the function returned an error: "github token is not set".

This PR changes the behavior so that when no token source is available, an unauthenticated HTTP client is used to create the GitHub client instead of returning an error. This allows:

  • Creating a Github instance without a token (e.g., for public repositories)
  • Git operations that don't require API authentication to proceed normally
  • API operations requiring authentication will still fail at call time with an appropriate error from GitHub

A debug log message is emitted to warn users that authenticated API operations may fail.

Test

  go test ./pkg/plugins/scms/github/... -run TestNew -v     

Additional Information

Why this approach

Option B from the issue was chosen over simply updating the test expectation (wantErr: true), because the test name No_Error_for_missing_token reflects the intended design: a missing token should
not be a fatal error at client creation time. The failure should happen lazily, only when an authenticated API call is actually attempted.

Changes

  • pkg/plugins/scms/github/client/main.go: When tokenSource == nil, create an unauthenticated client using the retry HTTP client instead of returning an error. Removed unused errors import.

Copy link
Copy Markdown
Member

@olblak olblak left a comment

Choose a reason for hiding this comment

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

Thank you for the fix

@olblak olblak merged commit 384b611 into updatecli:main Mar 22, 2026
7 checks passed
@olblak olblak added the enhancement New feature or request label Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GitHub SCM Plugin: Test Failure - Token Validation Mismatch

2 participants