From fb7d5b6a93336b36e0acc570df29e03dc82969a3 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Tue, 18 Nov 2025 14:43:47 -0300 Subject: [PATCH] style: small code style updates --- internal/app/app.go | 1 + internal/update/update.go | 16 +++++++--------- internal/update/update_test.go | 2 ++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/internal/app/app.go b/internal/app/app.go index 847eb7161bf1a67ab6611ef566c30072600c000d..c3748b15070324e9fa438b7ff56f15f76375974a 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -400,6 +400,7 @@ func (app *App) Shutdown() { func (app *App) checkForUpdates(ctx context.Context) { checkCtx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() + info, err := update.Check(checkCtx, version.Version, update.Default) if err != nil || !info.Available() { return diff --git a/internal/update/update.go b/internal/update/update.go index 1ddda8eca17e19077b26c3da09de6c129316f019..0a3178d818207f11a7f46560065c4d47e8a1f5e7 100644 --- a/internal/update/update.go +++ b/internal/update/update.go @@ -11,7 +11,7 @@ import ( ) const ( - githubAPIURL = "https://api.github.com/repos/charmbracelet/crush/releases/latest" + githubApiUrl = "https://api.github.com/repos/charmbracelet/crush/releases/latest" userAgent = "crush/1.0" ) @@ -34,13 +34,11 @@ type Info struct { func (i Info) Available() bool { cpr := strings.Contains(i.Current, "-") lpr := strings.Contains(i.Latest, "-") - // current is pre release - if cpr { - // latest isn't a prerelease - if !lpr { - return true - } + // current is pre release && latest isn't a prerelease + if cpr && !lpr { + return true } + // latest is pre release && current isn't a prerelease if lpr && !cpr { return false } @@ -88,7 +86,7 @@ func (c *github) Latest(ctx context.Context) (*Release, error) { Timeout: 30 * time.Second, } - req, err := http.NewRequestWithContext(ctx, "GET", githubAPIURL, nil) + req, err := http.NewRequestWithContext(ctx, "GET", githubApiUrl, nil) if err != nil { return nil, err } @@ -103,7 +101,7 @@ func (c *github) Latest(ctx context.Context) (*Release, error) { if resp.StatusCode != http.StatusOK { body, _ := io.ReadAll(resp.Body) - return nil, fmt.Errorf("GitHub API returned status %d: %s", resp.StatusCode, string(body)) + return nil, fmt.Errorf("github api returned status %d: %s", resp.StatusCode, string(body)) } var release Release diff --git a/internal/update/update_test.go b/internal/update/update_test.go index e833ad220705837a0f18cbc4b6abf6338987644c..488c7dfd4b29dec4dfe5d13958c13dcb914e5961 100644 --- a/internal/update/update_test.go +++ b/internal/update/update_test.go @@ -28,12 +28,14 @@ func TestCheckForUpdate_Beta(t *testing.T) { require.NotNil(t, info) require.False(t, info.Available()) }) + t.Run("current is also beta", func(t *testing.T) { info, err := Check(t.Context(), "v0.11.0-beta.1", testClient{"v0.11.0-beta.2"}) require.NoError(t, err) require.NotNil(t, info) require.True(t, info.Available()) }) + t.Run("current is beta, latest isn't", func(t *testing.T) { info, err := Check(t.Context(), "v0.11.0-beta.1", testClient{"v0.11.0"}) require.NoError(t, err)