diff --git a/go.mod b/go.mod index baab9a10f..136246fde 100644 --- a/go.mod +++ b/go.mod @@ -34,7 +34,6 @@ require ( github.com/google/go-cmp v0.7.0 github.com/google/go-containerregistry v0.21.7 github.com/google/go-containerregistry/pkg/authn/kubernetes v0.0.0-20260624172245-e8b2b9e51df6 - github.com/google/go-github/v74 v74.0.0 github.com/google/go-github/v88 v88.0.0 github.com/google/uuid v1.6.0 github.com/gorilla/handlers v1.5.2 @@ -186,6 +185,7 @@ require ( github.com/google/btree v1.1.3 // indirect github.com/google/cel-go v0.26.1 // indirect github.com/google/gnostic-models v0.7.1 // indirect + github.com/google/go-github/v74 v74.0.0 // indirect github.com/google/go-querystring v1.2.0 // indirect github.com/google/jsonschema-go v0.4.3 // indirect github.com/google/pprof v0.0.0-20260402051712-545e8a4df936 // indirect diff --git a/go.sum b/go.sum index 77dd7d3b0..94ae86bf8 100644 --- a/go.sum +++ b/go.sum @@ -382,6 +382,7 @@ github.com/google/go-containerregistry/pkg/authn/kubernetes v0.0.0-2026062417224 github.com/google/go-containerregistry/pkg/authn/kubernetes v0.0.0-20260624172245-e8b2b9e51df6/go.mod h1:s7sqcjbMmrp83ZR+yfMnM4jn8Rtooh7yAtOGNLBUNWM= github.com/google/go-github/v74 v74.0.0 h1:yZcddTUn8DPbj11GxnMrNiAnXH14gNs559AsUpNpPgM= github.com/google/go-github/v74 v74.0.0/go.mod h1:ubn/YdyftV80VPSI26nSJvaEsTOnsjrxG3o9kJhcyak= +github.com/google/go-github/v88 v88.0.0 h1:dZA9IKkPK1eXZj4ypngnpRj5FwdpTv4whix2PrQMP7M= github.com/google/go-github/v88 v88.0.0/go.mod h1:rufTDgn2N45wjhukLTyxmvc9nilSp3mr3Rgtt6b1MPw= github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfhIxNtP0= github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU= diff --git a/pkg/selfupdate/source.go b/pkg/selfupdate/source.go index 9b0a53f0a..a2a32d8e5 100644 --- a/pkg/selfupdate/source.go +++ b/pkg/selfupdate/source.go @@ -4,9 +4,10 @@ import ( "context" "fmt" "os" + "time" "github.com/creativeprojects/go-selfupdate" - "github.com/google/go-github/v74/github" + "github.com/google/go-github/v88/github" ) const releasesPerPage = 100 @@ -23,9 +24,13 @@ func newAllPagesSource() (*allPagesSource, error) { if err != nil { return nil, err } - client := github.NewClient(nil) + var opts []github.ClientOptionsFunc if token := os.Getenv("GITHUB_TOKEN"); token != "" { - client = client.WithAuthToken(token) + opts = append(opts, github.WithAuthToken(token)) + } + client, err := github.NewClient(opts...) + if err != nil { + return nil, err } return &allPagesSource{GitHubSource: base, api: client}, nil } @@ -47,7 +52,7 @@ func (s *allPagesSource) ListReleases( return nil, fmt.Errorf("list releases for %s/%s: %w", owner, repo, err) } for _, rel := range page { - releases = append(releases, selfupdate.NewGitHubRelease(rel)) + releases = append(releases, newSourceRelease(rel)) } if resp.NextPage == 0 { break @@ -56,3 +61,42 @@ func (s *allPagesSource) ListReleases( } return releases, nil } + +// sourceRelease adapts a go-github RepositoryRelease to selfupdate.SourceRelease. +// It exists so this package can track a newer go-github version than the one +// go-selfupdate's NewGitHubRelease is compiled against. +type sourceRelease struct { + *github.RepositoryRelease +} + +func newSourceRelease(rel *github.RepositoryRelease) sourceRelease { + return sourceRelease{RepositoryRelease: rel} +} + +func (r sourceRelease) GetReleaseNotes() string { return r.GetBody() } +func (r sourceRelease) GetURL() string { return r.GetHTMLURL() } +func (r sourceRelease) GetPublishedAt() time.Time { + return r.RepositoryRelease.GetPublishedAt().Time +} + +func (r sourceRelease) GetAssets() []selfupdate.SourceAsset { + assets := make([]selfupdate.SourceAsset, len(r.Assets)) + for i, a := range r.Assets { + assets[i] = sourceAsset{ReleaseAsset: a} + } + return assets +} + +// sourceAsset adapts a go-github ReleaseAsset to selfupdate.SourceAsset. +type sourceAsset struct { + *github.ReleaseAsset +} + +func (a sourceAsset) GetBrowserDownloadURL() string { + return a.ReleaseAsset.GetBrowserDownloadURL() +} + +var ( + _ selfupdate.SourceRelease = sourceRelease{} + _ selfupdate.SourceAsset = sourceAsset{} +) diff --git a/pkg/selfupdate/source_test.go b/pkg/selfupdate/source_test.go index 4430aa772..3b01c4b18 100644 --- a/pkg/selfupdate/source_test.go +++ b/pkg/selfupdate/source_test.go @@ -5,11 +5,10 @@ import ( "fmt" "net/http" "net/http/httptest" - "net/url" "testing" "github.com/creativeprojects/go-selfupdate" - "github.com/google/go-github/v74/github" + "github.com/google/go-github/v88/github" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -34,10 +33,9 @@ func TestAllPagesSourceListReleasesPaginates(t *testing.T) { })) defer srv.Close() - client := github.NewClient(nil) - baseURL, err := url.Parse(srv.URL + "/") + baseURL := srv.URL + "/" + client, err := github.NewClient(github.WithURLs(&baseURL, &baseURL)) require.NoError(t, err) - client.BaseURL = baseURL src := &allPagesSource{api: client}