From a792d5aefd7e2f5a29b72c70bccb6aac6cf6ce86 Mon Sep 17 00:00:00 2001 From: Martin Englund Date: Tue, 24 Oct 2023 19:33:57 -0700 Subject: [PATCH] get latest version from github --- cmd/version.go | 22 +++++++++------------- main.go | 2 +- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/cmd/version.go b/cmd/version.go index 1cc3614..b47b190 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -58,20 +58,16 @@ func newVersionCmd() *cobra.Command { return &cmd } -// TODO change to HTTPS - -const VersionURL = "http://rockset.sh/install/version.json" - -type Versions struct { - Stable string `json:"stable"` - Beta string `json:"beta"` +type githubResponse struct { + Name string `json:"name"` } -func VersionCheck(ctx context.Context, ch chan string) { +func GithubVersionCheck(ctx context.Context, ch chan string) { // always send something on the channel defer func() { ch <- "" }() - request, err := http.NewRequestWithContext(ctx, http.MethodGet, VersionURL, nil) + request, err := http.NewRequestWithContext(ctx, http.MethodGet, + "https://api.github.com/repos/rockset/cli/releases/latest", nil) if err != nil { logger.Error("failed to create http request", "err", err) return @@ -84,14 +80,14 @@ func VersionCheck(ctx context.Context, ch chan string) { return } - var v Versions + var releases githubResponse dec := json.NewDecoder(response.Body) - if err = dec.Decode(&v); err != nil { + if err = dec.Decode(&releases); err != nil { logger.Error("failed to unmarshal json", "err", err) return } - if v.Stable != Version { - ch <- fmt.Sprintf("A new release of %s is available: %s → %s", tui.Rockset, Version, v.Stable) + if releases.Name != Version { + ch <- fmt.Sprintf("A new release of %s is available: %s → %s", tui.Rockset, Version, releases.Name) } } diff --git a/main.go b/main.go index b079d1a..045e44f 100644 --- a/main.go +++ b/main.go @@ -63,7 +63,7 @@ func main() { }() // kick off a version check in the background that will show up at the end of the run - go cmd.VersionCheck(versionCtx, version) + go cmd.GithubVersionCheck(versionCtx, version) root := cmd.NewRootCmd(Version) if err := root.ExecuteContext(ctx); err != nil {