Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
52 changes: 48 additions & 4 deletions pkg/selfupdate/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
Expand All @@ -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{}
)
8 changes: 3 additions & 5 deletions pkg/selfupdate/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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}

Expand Down
Loading