@@ -6,13 +6,15 @@ import (
66 "net/url"
77 "strings"
88
9- "github.com/gofri/go-github-ratelimit/github_ratelimit"
10- "github.com/google/go-github/v62/github"
119 "github.com/jetstack/version-checker/pkg/api"
10+
11+ "github.com/gofri/go-github-ratelimit/github_ratelimit"
12+ "github.com/google/go-github/v70/github"
1213)
1314
1415type Options struct {
15- Token string
16+ Token string
17+ Hostname string
1618}
1719
1820type Client struct {
@@ -32,6 +34,12 @@ func New(opts Options) *Client {
3234 panic (err )
3335 }
3436 client := github .NewClient (ghRateLimiter ).WithAuthToken (opts .Token )
37+ if opts .Hostname != "" {
38+ client , err = client .WithEnterpriseURLs (fmt .Sprintf ("https://%s/" , opts .Hostname ), fmt .Sprintf ("https://%s/api/uploads/" , opts .Hostname ))
39+ if err != nil {
40+ panic (fmt .Errorf ("setting enterprise URLs: %w" , err ))
41+ }
42+ }
3543
3644 return & Client {
3745 client : client ,
@@ -87,8 +95,8 @@ func (c *Client) determineGetAllVersionsFunc(ctx context.Context, owner, repo st
8795
8896func (c * Client ) buildPackageListOptions () * github.PackageListOptions {
8997 return & github.PackageListOptions {
90- PackageType : github .String ("container" ),
91- State : github .String ("active" ),
98+ PackageType : github .Ptr ("container" ),
99+ State : github .Ptr ("active" ),
92100 ListOptions : github.ListOptions {
93101 PerPage : 100 ,
94102 },
@@ -98,25 +106,28 @@ func (c *Client) buildPackageListOptions() *github.PackageListOptions {
98106func (c * Client ) extractImageTags (versions []* github.PackageVersion ) []api.ImageTag {
99107 var tags []api.ImageTag
100108 for _ , ver := range versions {
101- if len (ver .Metadata .Container .Tags ) == 0 {
102- continue
103- }
109+ if meta , ok := ver .GetMetadata (); ok {
104110
105- sha := ""
106- if strings .HasPrefix (* ver .Name , "sha" ) {
107- sha = * ver .Name
108- }
109-
110- for _ , tag := range ver .Metadata .Container .Tags {
111- if c .shouldSkipTag (tag ) {
111+ if len (meta .Container .Tags ) == 0 {
112112 continue
113113 }
114114
115- tags = append (tags , api.ImageTag {
116- Tag : tag ,
117- SHA : sha ,
118- Timestamp : ver .CreatedAt .Time ,
119- })
115+ sha := ""
116+ if strings .HasPrefix (* ver .Name , "sha" ) {
117+ sha = * ver .Name
118+ }
119+
120+ for _ , tag := range meta .Container .Tags {
121+ if c .shouldSkipTag (tag ) {
122+ continue
123+ }
124+
125+ tags = append (tags , api.ImageTag {
126+ Tag : tag ,
127+ SHA : sha ,
128+ Timestamp : ver .CreatedAt .Time ,
129+ })
130+ }
120131 }
121132 }
122133 return tags
0 commit comments