github.com/grahambrereton-form3/tilt@v0.10.18/internal/github/client.go (about) 1 package github 2 3 import ( 4 "context" 5 "strings" 6 7 "github.com/google/go-github/github" 8 "github.com/pkg/errors" 9 10 "github.com/windmilleng/tilt/pkg/model" 11 ) 12 13 type Client interface { 14 GetLatestRelease(ctx context.Context, org, repo string) (model.TiltBuild, error) 15 } 16 17 type ghClient struct { 18 client *github.Client 19 } 20 21 func NewClient() Client { 22 return ghClient{ 23 client: github.NewClient(nil), 24 } 25 } 26 27 func (cli ghClient) GetLatestRelease(ctx context.Context, org, repo string) (model.TiltBuild, error) { 28 release, _, err := cli.client.Repositories.GetLatestRelease(ctx, org, repo) 29 if err != nil { 30 return model.TiltBuild{}, errors.Wrapf(err, "error getting release for %s/%s", org, repo) 31 } 32 33 return model.TiltBuild{ 34 Version: strings.TrimPrefix(*release.Name, "v"), 35 Date: release.PublishedAt.Time.Format("2006-01-02"), 36 }, nil 37 }