feat: show a different message if crush is built from source

Andrey Nering created

Change summary

internal/app/app.go            | 1 +
internal/pubsub/events.go      | 1 +
internal/tui/tui.go            | 3 +++
internal/update/update.go      | 8 ++++----
internal/update/update_test.go | 7 -------
5 files changed, 9 insertions(+), 11 deletions(-)

Detailed changes

internal/app/app.go 🔗

@@ -408,5 +408,6 @@ func (app *App) checkForUpdates(ctx context.Context) {
 	app.events <- pubsub.UpdateAvailableMsg{
 		CurrentVersion: info.Current,
 		LatestVersion:  info.Latest,
+		IsDevelopment:  info.IsDevelopment(),
 	}
 }

internal/pubsub/events.go 🔗

@@ -31,4 +31,5 @@ type (
 type UpdateAvailableMsg struct {
 	CurrentVersion string
 	LatestVersion  string
+	IsDevelopment  bool
 }

internal/tui/tui.go 🔗

@@ -376,6 +376,9 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 	case pubsub.UpdateAvailableMsg:
 		// Show update notification in status bar
 		statusMsg := fmt.Sprintf("Crush update available: v%s → v%s.", msg.CurrentVersion, msg.LatestVersion)
+		if msg.IsDevelopment {
+			statusMsg = fmt.Sprintf("This is a development version of Crush. The latest version is v%s.", msg.LatestVersion)
+		}
 		s, statusCmd := a.status.Update(util.InfoMsg{
 			Type: util.InfoTypeInfo,
 			Msg:  statusMsg,

internal/update/update.go 🔗

@@ -25,6 +25,10 @@ type Info struct {
 	URL     string
 }
 
+func (i Info) IsDevelopment() bool {
+	return i.Current == "devel" || i.Current == "unknown" || strings.Contains(i.Current, "dirty")
+}
+
 // Available returns true if there's an update available.
 //
 // If both current and latest are stable versions, returns true if versions are
@@ -52,10 +56,6 @@ func Check(ctx context.Context, current string, client Client) (Info, error) {
 		Latest:  current,
 	}
 
-	if info.Current == "devel" || info.Current == "unknown" || strings.Contains(info.Current, "dirty") {
-		return info, nil
-	}
-
 	release, err := client.Latest(ctx)
 	if err != nil {
 		return info, fmt.Errorf("failed to fetch latest release: %w", err)

internal/update/update_test.go 🔗

@@ -7,13 +7,6 @@ import (
 	"github.com/stretchr/testify/require"
 )
 
-func TestCheckForUpdate_DevelopmentVersion(t *testing.T) {
-	info, err := Check(t.Context(), "unknown", testClient{"v0.11.0"})
-	require.NoError(t, err)
-	require.NotNil(t, info)
-	require.False(t, info.Available())
-}
-
 func TestCheckForUpdate_Old(t *testing.T) {
 	info, err := Check(t.Context(), "v0.10.0", testClient{"v0.11.0"})
 	require.NoError(t, err)