Skip to content

Commit c395bf5

Browse files
authored
Merge pull request #32 from jferrl/dev/jorge/remove-dev
refactor!: remove go-github dependency and implement internal GitHub API client
2 parents c78f523 + 003d736 commit c395bf5

File tree

8 files changed

+653
-48
lines changed

8 files changed

+653
-48
lines changed

CHANGELOG.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,103 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [v1.5.0] - 2025-10-28
9+
10+
### 🚨 Breaking Changes
11+
12+
This release removes the `github.com/google/go-github/v74` dependency and implements a lightweight internal GitHub API client. While most users will experience no breaking changes, some API adjustments have been made:
13+
14+
#### API Changes
15+
16+
1. **Enterprise Configuration Simplified**
17+
- **Before**: `WithEnterpriseURLs(baseURL, uploadURL string)` - required both base and upload URLs
18+
- **After**: `WithEnterpriseURL(baseURL string)` - single base URL parameter
19+
- **Migration**: Remove the redundant upload URL parameter
20+
21+
2. **Type Changes** (if you were using these types directly)
22+
- `github.InstallationTokenOptions``githubauth.InstallationTokenOptions`
23+
- `github.InstallationPermissions``githubauth.InstallationPermissions`
24+
- `github.InstallationToken``githubauth.InstallationToken`
25+
- `github.Repository``githubauth.Repository`
26+
27+
### Added
28+
29+
- **Internal GitHub API Client**: New `github.go` file with minimal GitHub API implementation
30+
- Direct HTTP API calls to GitHub's REST API
31+
- `InstallationTokenOptions` type for configuring installation token requests
32+
- `InstallationPermissions` type with comprehensive permission structure
33+
- `InstallationToken` response type from GitHub API
34+
- `Repository` type for minimal repository representation
35+
- **Public Helper Function**: Added `Ptr[T]()` generic helper for creating pointers to any type (useful for InstallationTokenOptions)
36+
37+
### Changed
38+
39+
- **Removed Dependency**: Eliminated `github.com/google/go-github/v74` dependency
40+
- **Removed Dependency**: Eliminated `github.com/google/go-querystring` indirect dependency
41+
- **Simplified Enterprise Support**: Streamlined from `WithEnterpriseURLs()` to `WithEnterpriseURL()`
42+
- **Updated Documentation**: Package docs now reflect that the library is built only on `golang.org/x/oauth2`
43+
- **Binary Size Reduction**: Smaller binaries without unused go-github code
44+
45+
### Fixed
46+
47+
- **Documentation**: Fixed GitHub API documentation link for installation token generation
48+
49+
### Migration Guide
50+
51+
#### For Most Users
52+
53+
No action required - if you only use the public `TokenSource` functions, your code will continue to work without changes.
54+
55+
#### For Enterprise GitHub Users
56+
57+
```go
58+
// Before (v1.4.x)
59+
installationTokenSource := githubauth.NewInstallationTokenSource(
60+
installationID,
61+
appTokenSource,
62+
githubauth.WithEnterpriseURLs("https://github.example.com", "https://github.example.com"),
63+
)
64+
65+
// After (v1.5.0)
66+
installationTokenSource := githubauth.NewInstallationTokenSource(
67+
installationID,
68+
appTokenSource,
69+
githubauth.WithEnterpriseURL("https://github.example.com"),
70+
)
71+
```
72+
73+
#### For Direct Type Users
74+
75+
```go
76+
// Before (v1.4.x)
77+
import "github.com/google/go-github/v74/github"
78+
opts := &github.InstallationTokenOptions{
79+
Repositories: []string{"repo1", "repo2"},
80+
Permissions: &github.InstallationPermissions{
81+
Contents: github.Ptr("read"),
82+
},
83+
}
84+
85+
// After (v1.5.0)
86+
import "github.com/jferrl/go-githubauth"
87+
opts := &githubauth.InstallationTokenOptions{
88+
Repositories: []string{"repo1", "repo2"},
89+
Permissions: &githubauth.InstallationPermissions{
90+
Contents: githubauth.Ptr("read"), // Use the new Ptr() helper
91+
},
92+
}
93+
```
94+
95+
### Benefits
96+
97+
-**Reduced Dependencies**: 2 fewer dependencies (from 3 to 2 total)
98+
-**Smaller Binary Size**: No unused go-github code included
99+
-**Better Control**: Full ownership of GitHub API integration
100+
-**Easier Debugging**: Simpler code path for troubleshooting
101+
-**Same Performance**: All token caching and performance optimizations maintained
102+
103+
**Full Changelog**: <https://github.com/jferrl/go-githubauth/compare/v1.4.2...v1.5.0>
104+
8105
## [v1.4.2] - 2025-09-19
9106

10107
### Changed

README.md

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
`go-githubauth` is a Go package that provides utilities for GitHub authentication, including generating and using GitHub App tokens, installation tokens, and personal access tokens.
1010

11-
**v1.4.x** introduces personal access token support and significant performance optimizations with intelligent token caching and high-performance HTTP clients.
11+
**v1.5.0** removes the `go-github` dependency, implementing a lightweight internal GitHub API client. This reduces external dependencies while maintaining full compatibility with the OAuth2 token source interface.
1212

1313
---
1414

@@ -26,15 +26,17 @@
2626

2727
`go-githubauth` package provides implementations of the `TokenSource` interface from the `golang.org/x/oauth2` package. This interface has a single method, Token, which returns an *oauth2.Token.
2828

29-
### v1.4.0 Features
29+
### v1.5.0 Features
3030

31+
- **📦 Zero External Dependencies**: Removed `go-github` dependency - lightweight internal implementation
3132
- **🔐 Personal Access Token Support**: Native support for both classic and fine-grained personal access tokens
3233
- **⚡ Token Caching**: Dual-layer caching system for optimal performance
3334
- JWT tokens cached until expiration (up to 10 minutes)
3435
- Installation tokens cached until expiration (defined by GitHub response)
3536
- **🚀 Pooled HTTP Client**: Production-ready HTTP client with connection pooling
3637
- **📈 Performance Optimizations**: Up to 99% reduction in unnecessary GitHub API calls
3738
- **🏗️ Production Ready**: Optimized for high-throughput and enterprise applications
39+
- **🌐 Simplified Enterprise Support**: Streamlined configuration with single base URL parameter
3840

3941
### Core Capabilities
4042

@@ -48,7 +50,9 @@
4850

4951
### Requirements
5052

53+
- Go 1.21 or higher (for generics support)
5154
- This package is designed to be used with the `golang.org/x/oauth2` package
55+
- No external GitHub SDK dependencies required
5256

5357
## Installation
5458

@@ -60,7 +64,9 @@ go get -u github.com/jferrl/go-githubauth
6064

6165
## Usage
6266

63-
### Usage with [go-github](https://github.com/google/go-github) and [oauth2](golang.org/x/oauth2)
67+
### Usage with [oauth2](golang.org/x/oauth2)
68+
69+
You can use this package standalone with any HTTP client, or integrate it with the [go-github](https://github.com/google/go-github) SDK if you need additional GitHub API functionality.
6470

6571
#### Client ID (Recommended)
6672

@@ -73,7 +79,7 @@ import (
7379
"os"
7480
"strconv"
7581

76-
"github.com/google/go-github/v74/github"
82+
"github.com/google/go-github/v76/github"
7783
"github.com/jferrl/go-githubauth"
7884
"golang.org/x/oauth2"
7985
)
@@ -117,7 +123,7 @@ import (
117123
"os"
118124
"strconv"
119125

120-
"github.com/google/go-github/v74/github"
126+
"github.com/google/go-github/v76/github"
121127
"github.com/jferrl/go-githubauth"
122128
"golang.org/x/oauth2"
123129
)
@@ -274,7 +280,48 @@ func main() {
274280

275281
GitHub Personal Access Tokens provide direct authentication for users and organizations. This package supports both classic personal access tokens and fine-grained personal access tokens.
276282

277-
#### Using Personal Access Tokens with [go-github](https://github.com/google/go-github)
283+
#### Using Personal Access Tokens
284+
285+
##### With oauth2 Client (Standalone)
286+
287+
```go
288+
package main
289+
290+
import (
291+
"context"
292+
"fmt"
293+
"io"
294+
"net/http"
295+
"os"
296+
297+
"github.com/jferrl/go-githubauth"
298+
"golang.org/x/oauth2"
299+
)
300+
301+
func main() {
302+
// Personal access token from environment variable
303+
token := os.Getenv("GITHUB_TOKEN") // e.g., "ghp_..." or "github_pat_..."
304+
305+
// Create token source
306+
tokenSource := githubauth.NewPersonalAccessTokenSource(token)
307+
308+
// Create HTTP client with OAuth2 transport
309+
httpClient := oauth2.NewClient(context.Background(), tokenSource)
310+
311+
// Use the HTTP client for GitHub API calls
312+
resp, err := httpClient.Get("https://api.github.com/user")
313+
if err != nil {
314+
fmt.Println("Error getting user:", err)
315+
return
316+
}
317+
defer resp.Body.Close()
318+
319+
body, _ := io.ReadAll(resp.Body)
320+
fmt.Printf("User info: %s\n", body)
321+
}
322+
```
323+
324+
##### With go-github SDK (Optional)
278325

279326
```go
280327
package main
@@ -284,7 +331,7 @@ import (
284331
"fmt"
285332
"os"
286333

287-
"github.com/google/go-github/v74/github"
334+
"github.com/google/go-github/v76/github"
288335
"github.com/jferrl/go-githubauth"
289336
"golang.org/x/oauth2"
290337
)
@@ -316,7 +363,7 @@ func main() {
316363
1. **Classic Personal Access Token**: Visit [GitHub Settings > Developer settings > Personal access tokens > Tokens (classic)](https://github.com/settings/tokens)
317364
2. **Fine-grained Personal Access Token**: Visit [GitHub Settings > Developer settings > Personal access tokens > Fine-grained tokens](https://github.com/settings/personal-access-tokens/new)
318365

319-
** 🔐 Security Note **: Store your personal access tokens securely and never commit them to version control. Use environment variables or secure credential management systems.
366+
**🔐 Security Note**: Store your personal access tokens securely and never commit them to version control. Use environment variables or secure credential management systems.
320367

321368
## Contributing
322369

auth.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
// This package implements oauth2.TokenSource interfaces for GitHub App
55
// authentication and GitHub App installation token generation. It is built
6-
// on top of the go-github and golang.org/x/oauth2 libraries.
6+
// on top of the golang.org/x/oauth2 library.
77
package githubauth
88

99
import (
@@ -15,7 +15,6 @@ import (
1515
"time"
1616

1717
jwt "github.com/golang-jwt/jwt/v5"
18-
"github.com/google/go-github/v74/github"
1918
"golang.org/x/oauth2"
2019
)
2120

@@ -135,7 +134,7 @@ func (t *applicationTokenSource) Token() (*oauth2.Token, error) {
135134
type InstallationTokenSourceOpt func(*installationTokenSource)
136135

137136
// WithInstallationTokenOptions sets the options for the GitHub App installation token.
138-
func WithInstallationTokenOptions(opts *github.InstallationTokenOptions) InstallationTokenSourceOpt {
137+
func WithInstallationTokenOptions(opts *InstallationTokenOptions) InstallationTokenSourceOpt {
139138
return func(i *installationTokenSource) {
140139
i.opts = opts
141140
}
@@ -149,16 +148,16 @@ func WithHTTPClient(client *http.Client) InstallationTokenSourceOpt {
149148
Base: client.Transport,
150149
}
151150

152-
i.client = github.NewClient(client)
151+
i.client = newGitHubClient(client)
153152
}
154153
}
155154

156-
// WithEnterpriseURLs sets the base URL and upload URL for GitHub Enterprise Server.
155+
// WithEnterpriseURL sets the base URL for GitHub Enterprise Server.
157156
// This option should be used after WithHTTPClient to ensure the HTTP client is properly configured.
158-
// If the provided URLs are invalid, the option is ignored and default GitHub URLs are used.
159-
func WithEnterpriseURLs(baseURL, uploadURL string) InstallationTokenSourceOpt {
157+
// If the provided base URL is invalid, the option is ignored and default GitHub base URL is used.
158+
func WithEnterpriseURL(baseURL string) InstallationTokenSourceOpt {
160159
return func(i *installationTokenSource) {
161-
enterpriseClient, err := i.client.WithEnterpriseURLs(baseURL, uploadURL)
160+
enterpriseClient, err := i.client.withEnterpriseURL(baseURL)
162161
if err != nil {
163162
return
164163
}
@@ -182,8 +181,8 @@ type installationTokenSource struct {
182181
id int64
183182
ctx context.Context
184183
src oauth2.TokenSource
185-
client *github.Client
186-
opts *github.InstallationTokenOptions
184+
client *githubClient
185+
opts *InstallationTokenOptions
187186
}
188187

189188
// NewInstallationTokenSource creates a GitHub App installation token source.
@@ -193,7 +192,7 @@ type installationTokenSource struct {
193192
// token regeneration. Don't worry about wrapping the result again since ReuseTokenSource
194193
// prevents re-wrapping automatically.
195194
//
196-
// See https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-an-installation-access-token
195+
// See https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-an-installation-access-token-for-a-github-app
197196
func NewInstallationTokenSource(id int64, src oauth2.TokenSource, opts ...InstallationTokenSourceOpt) oauth2.TokenSource {
198197
ctx := context.Background()
199198

@@ -207,7 +206,7 @@ func NewInstallationTokenSource(id int64, src oauth2.TokenSource, opts ...Instal
207206
id: id,
208207
ctx: ctx,
209208
src: src,
210-
client: github.NewClient(httpClient),
209+
client: newGitHubClient(httpClient),
211210
}
212211

213212
for _, opt := range opts {
@@ -219,15 +218,15 @@ func NewInstallationTokenSource(id int64, src oauth2.TokenSource, opts ...Instal
219218

220219
// Token generates a new GitHub App installation token for authenticating as a GitHub App installation.
221220
func (t *installationTokenSource) Token() (*oauth2.Token, error) {
222-
token, _, err := t.client.Apps.CreateInstallationToken(t.ctx, t.id, t.opts)
221+
token, err := t.client.createInstallationToken(t.ctx, t.id, t.opts)
223222
if err != nil {
224223
return nil, err
225224
}
226225

227226
return &oauth2.Token{
228-
AccessToken: token.GetToken(),
227+
AccessToken: token.Token,
229228
TokenType: bearerTokenType,
230-
Expiry: token.GetExpiresAt().Time,
229+
Expiry: token.ExpiresAt,
231230
}, nil
232231
}
233232

0 commit comments

Comments
 (0)