- 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.
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/fatih/color"
|
|
"github.com/spf13/cobra"
|
|
"gmgauthier.com/grokkit/config"
|
|
)
|
|
|
|
var prDescribeCmd = &cobra.Command{
|
|
Use: "pr-describe",
|
|
Short: "Generate full PR description from current branch",
|
|
Run: runPRDescribe,
|
|
}
|
|
|
|
func runPRDescribe(cmd *cobra.Command, args []string) {
|
|
diff, err := gitRun([]string{"diff", "main..HEAD", "--no-color"})
|
|
if err != nil || diff == "" {
|
|
diff, err = gitRun([]string{"diff", "origin/main..HEAD", "--no-color"})
|
|
if err != nil {
|
|
color.Red("Failed to get branch diff: %v", err)
|
|
return
|
|
}
|
|
}
|
|
if diff == "" {
|
|
color.Yellow("No changes on this branch compared to main/origin/main.")
|
|
return
|
|
}
|
|
modelFlag, _ := cmd.Flags().GetString("model")
|
|
model := config.GetModel("prdescribe", modelFlag)
|
|
|
|
client := newGrokClient()
|
|
messages := buildPRDescribeMessages(diff)
|
|
color.Yellow("Writing PR description...")
|
|
client.Stream(messages, model)
|
|
}
|
|
|
|
func buildPRDescribeMessages(diff string) []map[string]string {
|
|
return []map[string]string{
|
|
{"role": "system", "content": "Write a professional GitHub PR title + detailed body (changes, motivation, testing notes)."},
|
|
{"role": "user", "content": fmt.Sprintf("Diff:\n%s", diff)},
|
|
}
|
|
}
|