From cbc521467a3cca7a17e6f691a9c7fa34f4da3e24 Mon Sep 17 00:00:00 2001 From: s Date: Wed, 26 Nov 2025 05:11:14 -0500 Subject: refactor: remove changelog display and simplify update output --- cmd/update.go | 182 +--------------------------------------------- internal/utils/version.go | 6 +- 2 files changed, 6 insertions(+), 182 deletions(-) diff --git a/cmd/update.go b/cmd/update.go index f7956ea..a9df463 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -4,9 +4,8 @@ import ( "fmt" "os" "os/exec" - "regexp" + "runtime/debug" - "sort" "strings" "git.db.org.ai/dborg/internal/utils" @@ -33,173 +32,6 @@ func getLatestVersion() (string, error) { return strings.TrimSpace(parts[1]), nil } -func getAllTags() ([]string, error) { - cmd := exec.Command("git", "ls-remote", "--tags", "--refs", utils.RepositoryURL) - output, err := cmd.Output() - if err != nil { - return nil, err - } - - var tags []string - lines := strings.Split(strings.TrimSpace(string(output)), "\n") - for _, line := range lines { - if line == "" { - continue - } - - parts := strings.Split(line, "refs/tags/") - if len(parts) < 2 { - continue - } - - tag := strings.TrimSpace(parts[1]) - tags = append(tags, tag) - } - - sort.Slice(tags, func(i, j int) bool { - return tags[i] > tags[j] - }) - - return tags, nil -} - -type Commit struct { - Type string - Scope string - Description string - Hash string -} - -func getCommitsBetweenVersions(fromVersion, toVersion string) ([]Commit, error) { - var commits []Commit - - fromTag := "" - if fromVersion != "" { - fromTag = fmt.Sprintf("v%s", strings.TrimPrefix(fromVersion, "v")) - } - toTag := fmt.Sprintf("v%s", strings.TrimPrefix(toVersion, "v")) - - var rangeSpec string - if fromTag == "" { - rangeSpec = toTag - } else { - rangeSpec = fmt.Sprintf("%s..%s", fromTag, toTag) - } - - cmd := exec.Command("git", "log", "--oneline", "--no-merges", rangeSpec, "--", utils.RepositoryURL) - output, err := cmd.Output() - if err != nil { - return nil, fmt.Errorf("failed to fetch commits: %w", err) - } - - lines := strings.Split(strings.TrimSpace(string(output)), "\n") - for _, line := range lines { - if line == "" { - continue - } - - parts := strings.SplitN(line, " ", 2) - if len(parts) < 2 { - continue - } - - hash := parts[0] - message := parts[1] - - commit := parseCommitMessage(hash, message) - commits = append(commits, commit) - } - - return commits, nil -} - -func parseCommitMessage(hash, message string) Commit { - re := regexp.MustCompile(`^(\w+)(?:\(([^)]+)\))?:\s*(.+)$`) - matches := re.FindStringSubmatch(message) - - if len(matches) == 4 { - return Commit{ - Type: matches[1], - Scope: matches[2], - Description: matches[3], - Hash: hash, - } - } - - return Commit{ - Type: "chore", - Description: message, - Hash: hash, - } -} - -func displayCommits(commits []Commit) { - if len(commits) == 0 { - fmt.Println("No changes found.") - return - } - - categories := make(map[string][]Commit) - for _, commit := range commits { - categories[commit.Type] = append(categories[commit.Type], commit) - } - - typeOrder := []string{"feat", "fix", "perf", "refactor", "docs", "style", "test", "chore", "build", "ci"} - - fmt.Println("\nšŸ“‹ What's new:") - fmt.Println(strings.Repeat("═", 50)) - - for _, commitType := range typeOrder { - if commits, exists := categories[commitType]; exists { - displayCategory(commitType, commits) - delete(categories, commitType) - } - } - - for commitType, commits := range categories { - displayCategory(commitType, commits) - } - - fmt.Println(strings.Repeat("═", 50)) -} - -func displayCategory(commitType string, commits []Commit) { - var icon string - switch commitType { - case "feat": - icon = "✨" - case "fix": - icon = "šŸ›" - case "perf": - icon = "⚔" - case "refactor": - icon = "ā™»ļø" - case "docs": - icon = "šŸ“" - case "style": - icon = "šŸ’„" - case "test": - icon = "āœ…" - case "chore": - icon = "šŸ”§" - case "build": - icon = "šŸ“¦" - case "ci": - icon = "šŸ¤–" - default: - icon = "šŸ“Œ" - } - - fmt.Printf("\n%s %s\n", icon, strings.ToUpper(commitType)) - for _, commit := range commits { - if commit.Scope != "" { - fmt.Printf(" • %s (%s): %s\n", commit.Description, commit.Scope, commit.Hash[:7]) - } else { - fmt.Printf(" • %s (%s)\n", commit.Description, commit.Hash[:7]) - } - } -} - var updateCmd = &cobra.Command{ Use: "update", Short: "Update dborg to the latest version", @@ -226,15 +58,7 @@ var updateCmd = &cobra.Command{ } fmt.Printf("Updating from %s to %s...\n", currentVersion, latestVersion) - - commits, err := getCommitsBetweenVersions(currentVersion, latestVersion) - if err != nil { - fmt.Fprintf(os.Stderr, "Warning: Could not fetch commit changes: %v\n", err) - } else { - displayCommits(commits) - } - - fmt.Printf("\nšŸš€ Installing dborg %s...\n", latestVersion) + fmt.Printf("Installing dborg %s...\n", latestVersion) installTarget := fmt.Sprintf("git.db.org.ai/dborg@%s", latestVersion) installCmd := exec.Command("go", "install", installTarget) @@ -246,7 +70,7 @@ var updateCmd = &cobra.Command{ os.Exit(1) } - fmt.Printf("\nāœ… dborg updated successfully to %s!\n", latestVersion) + fmt.Printf("Updated to %s\n", latestVersion) }, } diff --git a/internal/utils/version.go b/internal/utils/version.go index b6ae282..46ebb73 100644 --- a/internal/utils/version.go +++ b/internal/utils/version.go @@ -13,7 +13,7 @@ import ( var ( Version = "dev" - RepositoryURL = "https://git.db.org.ai/dborg.git" + RepositoryURL = "https://git.db.org.ai/dborg" ) func init() { @@ -95,7 +95,7 @@ func isNewerVersion(remote, local string) bool { } func promptAndUpdate(newVersion string) { - fmt.Fprintf(os.Stderr, "\nšŸ”” A new version of dborg is available: %s (current: %s)\n", newVersion, Version) + fmt.Fprintf(os.Stderr, "\nNew version available: %s (current: %s)\n", newVersion, Version) fmt.Fprintf(os.Stderr, "Would you like to update now? [Y/n]: ") var response string @@ -120,7 +120,7 @@ func promptAndUpdate(newVersion string) { return } - fmt.Fprintf(os.Stderr, "āœ“ Update successful! Restarting...\n\n") + fmt.Fprintf(os.Stderr, "Updated. Restarting...\n\n") restartSelf() } -- cgit v1.2.3