- Introduce newGrokClient and gitRun vars to allow mocking in tests. - Refactor commit, commitmsg, history, prdescribe, and review cmds into separate run funcs. - Update docs, lint, and review to use newGrokClient. - Add comprehensive unit tests in run_test.go covering happy paths, errors, and edge cases. - Expand grok client tests with SSE server mocks for Stream* methods.
41 lines
941 B
Go
41 lines
941 B
Go
package cmd
|
|
|
|
import (
|
|
"github.com/fatih/color"
|
|
"github.com/spf13/cobra"
|
|
"gmgauthier.com/grokkit/config"
|
|
)
|
|
|
|
var historyCmd = &cobra.Command{
|
|
Use: "history",
|
|
Short: "Summarize recent git history",
|
|
Run: runHistory,
|
|
}
|
|
|
|
func runHistory(cmd *cobra.Command, args []string) {
|
|
log, err := gitRun([]string{"log", "--oneline", "-10"})
|
|
if err != nil {
|
|
color.Red("Failed to get git log: %v", err)
|
|
return
|
|
}
|
|
if log == "" {
|
|
color.Yellow("No commits found.")
|
|
return
|
|
}
|
|
|
|
modelFlag, _ := cmd.Flags().GetString("model")
|
|
model := config.GetModel("history", modelFlag)
|
|
|
|
client := newGrokClient()
|
|
messages := buildHistoryMessages(log)
|
|
color.Yellow("Summarizing recent commits...")
|
|
client.Stream(messages, model)
|
|
}
|
|
|
|
func buildHistoryMessages(log string) []map[string]string {
|
|
return []map[string]string{
|
|
{"role": "system", "content": "Summarize the recent git history in 3-5 bullet points."},
|
|
{"role": "user", "content": log},
|
|
}
|
|
}
|