Skip to content

Conversation

@jferrl
Copy link
Owner

@jferrl jferrl commented Oct 28, 2025

Remove go-github Dependency and Implement Internal GitHub API Client

Summary

This PR eliminates the github.com/google/go-github/v74 dependency by implementing a lightweight internal GitHub API client. The change reduces external dependencies while maintaining 100% API compatibility with existing code.

Motivation

  • Reduce dependency footprint: The go-github library is a comprehensive SDK with many features we don't use
  • Better control: Direct implementation of the specific API endpoints we need
  • Lighter weight: Smaller binary size and fewer transitive dependencies
  • Simplified maintenance: Fewer external dependencies to track and update

Changes

New File: github.go

  • Added internal GitHub API types:
    • InstallationTokenOptions - configuration for installation token requests
    • InstallationPermissions - comprehensive permission structure
    • InstallationToken - GitHub API response type
    • Repository - minimal repository representation
  • Implemented githubClient with:
    • Direct HTTP API calls to GitHub's REST API
    • Proper JSON serialization/deserialization
    • Enterprise GitHub support via withEnterpriseURL()
    • Error handling with detailed messages
  • Added generic ptr[T]() helper for creating pointers

Modified: auth.go

  • Removed github.com/google/go-github/v74/github import
  • Updated all type references to use internal types
  • Simplified WithEnterpriseURLs() to WithEnterpriseURL() (single base URL parameter)
  • Updated package documentation to reflect new architecture
  • Fixed documentation link for installation token generation

Modified: auth_test.go

  • Removed go-github import from tests
  • Updated all test fixtures to use internal types
  • Replaced github.Ptr() with local ptr() helper
  • All tests passing without modification to test logic

Modified: go.mod and go.sum

  • Removed github.com/google/go-github/v74 v74.0.0
  • Removed indirect dependency github.com/google/go-querystring v1.1.0

API Compatibility

No breaking changes - The public API remains unchanged:

  • NewApplicationTokenSource() - unchanged
  • NewInstallationTokenSource() - unchanged
  • NewPersonalAccessTokenSource() - unchanged
  • WithInstallationTokenOptions() - type change but same usage pattern
  • WithEnterpriseURL() - simplified from WithEnterpriseURLs() (removed redundant upload URL parameter)

Testing

All existing tests pass without modification:

✓ TestNewApplicationTokenSource
✓ TestApplicationTokenSource_Token
✓ Test_installationTokenSource_Token
✓ TestNewPersonalAccessTokenSource
✓ TestPersonalAccessTokenSource_Token

Benefits

  1. Reduced Dependencies: 2 fewer dependencies in go.mod
  2. Smaller Binary: No unused go-github code included
  3. Better Performance: Direct API calls without abstraction overhead
  4. Full Control: Complete ownership of GitHub API integration
  5. Easier Debugging: Simpler code path for troubleshooting
  6. Enterprise Support: Streamlined configuration with single base URL

Migration Notes for Users

For Most Users

No action required - this change is transparent to existing code.

For Enterprise GitHub Users

If you were using WithEnterpriseURLs(baseURL, uploadURL):

// Before
installationTokenSource := githubauth.NewInstallationTokenSource(
    installationID, 
    appTokenSource,
    githubauth.WithEnterpriseURLs("https://github.example.com", "https://github.example.com"),
)

// After (uploadURL parameter removed)
installationTokenSource := githubauth.NewInstallationTokenSource(
    installationID, 
    appTokenSource,
    githubauth.WithEnterpriseURL("https://github.example.com"),
)

For Type Users

If you were directly referencing github.InstallationTokenOptions:

// Before
import "github.com/google/go-github/v74/github"
opts := &github.InstallationTokenOptions{...}

// After
import "github.com/jferrl/go-githubauth"
opts := &githubauth.InstallationTokenOptions{...}

Verification

  • ✅ All unit tests passing
  • ✅ No linter errors
  • ✅ go mod tidy completed successfully
  • ✅ API surface unchanged (except simplified enterprise configuration)
  • ✅ Documentation updated

…PI client

- Replace go-github/v74 dependency with lightweight internal implementation
- Add new github.go with minimal GitHub API types and client
- Update InstallationTokenOptions and InstallationPermissions to local types
- Simplify enterprise URL configuration to single base URL parameter
- All functionality maintained with same public API surface
- All tests passing with zero breaking changes
@codecov
Copy link

codecov bot commented Oct 28, 2025

Codecov Report

❌ Patch coverage is 84.00000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.20%. Comparing base (c78f523) to head (003d736).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
github.go 80.95% 4 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #32      +/-   ##
==========================================
- Coverage   94.28%   92.20%   -2.08%     
==========================================
  Files           2        3       +1     
  Lines         140      154      +14     
==========================================
+ Hits          132      142      +10     
- Misses          6        7       +1     
- Partials        2        5       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

BREAKING CHANGE: Remove go-github/v74 dependency and implement internal GitHub API client

Breaking Changes:
- WithEnterpriseURLs(baseURL, uploadURL) → WithEnterpriseURL(baseURL) - simplified to single parameter
- github.InstallationTokenOptions → githubauth.InstallationTokenOptions
- github.InstallationPermissions → githubauth.InstallationPermissions
- github.InstallationToken → githubauth.InstallationToken
- github.Repository → githubauth.Repository

Added:
- New github.go with lightweight GitHub API client
- InstallationTokenOptions and related types now internal
- Public Ptr[T]() helper function for creating pointers
- Support for direct HTTP API calls to GitHub

Changed:
- Removed github.com/google/go-github/v74 dependency
- Removed github.com/google/go-querystring indirect dependency
- Simplified enterprise configuration API
- Updated documentation for v1.5.0
- Updated README with standalone usage examples

Benefits:
- Reduced dependencies from 3 to 2
- Smaller binary size
- Better control over GitHub API integration
- All tests passing with zero functional changes
Wraps resp.Body.Close() in an anonymous function and ignores any error to prevent potential issues if closing the response body fails.
Added new tests in auth_test.go to cover signing errors and invalid enterprise URLs. Introduced github_test.go with comprehensive tests for GitHub client error paths, including invalid URLs, HTTP error responses, JSON decoding errors, and pointer utility function coverage.
- Explicitly ignore error returns from json.Encoder.Encode() with _
- Explicitly ignore error returns from w.Write() with _, _
- Change t.Error to t.Fatal for nil pointer checks to prevent SA5011 warnings
- All tests passing with no linter errors
@jferrl jferrl merged commit c395bf5 into main Oct 28, 2025
7 of 9 checks passed
@jferrl jferrl deleted the dev/jorge/remove-dev branch November 10, 2025 21:14
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.

2 participants