mirror of
https://github.com/prdlk/gh-commit.git
synced 2026-09-16 23:16:25 +00:00
feat: rewrite gh-commit in Go with local Ollama backend
Replaces the Python/Crush/DuckDB implementation with a CGO-free Go binary: cobra CLI, modernc.org/sqlite storage, huh/lipgloss UI, and speed-tuned raw /api/generate calls (think:false, keep_alive, capped num_predict) against a local qwen3.5:2b. Ships as a gh extension via cli/gh-extension-precompile.
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/prdlk/gh-commit/internal/gitx"
|
||||
"github.com/prdlk/gh-commit/internal/ui"
|
||||
)
|
||||
|
||||
var refreshCmd = &cobra.Command{
|
||||
Use: "refresh",
|
||||
Short: "Regenerate scopes from the current repository structure",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(_ *cobra.Command, _ []string) error {
|
||||
repoPath, err := requireGit()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
repoName := filepath.Base(repoPath)
|
||||
|
||||
hasScopes, err := store.HasScopes(repoPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !hasScopes {
|
||||
ui.Errorf("Repository not configured — run 'gh commit init' first")
|
||||
return errAborted
|
||||
}
|
||||
if err := ensureAI(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
existing, err := store.Scopes(repoPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ui.MagentaBoldf("Refreshing scopes for %s...", repoName)
|
||||
ui.Println()
|
||||
ui.Infof("Current scopes:")
|
||||
displayScopes(existing)
|
||||
ui.Println()
|
||||
|
||||
if !ui.Confirm("Refresh scopes based on current structure?") {
|
||||
ui.Dimf("Cancelled")
|
||||
return nil
|
||||
}
|
||||
|
||||
scopes := generateScopes(existing)
|
||||
if scopes == nil {
|
||||
return errAborted
|
||||
}
|
||||
|
||||
ui.Println()
|
||||
ui.Successf("✓ Generated updated scopes")
|
||||
ui.Println()
|
||||
ui.Magentaf("Updated scopes:")
|
||||
displayScopes(scopes)
|
||||
ui.Println()
|
||||
|
||||
if ui.Confirm("Apply these changes?") {
|
||||
if err := store.SaveScopes(repoPath, repoName, scopes, gitx.GitignoreHash(repoPath)); err != nil {
|
||||
return err
|
||||
}
|
||||
ui.Successf("✓ Updated scopes")
|
||||
} else {
|
||||
ui.Dimf("Changes not applied")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(refreshCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user