grokkit/cmd/prdescribe.go
Greg Gauthier b1d3a445ec
Some checks failed
Auto-complete TODO / move-todo (pull_request) Failing after 1s
CI / Test (pull_request) Successful in 34s
CI / Lint (pull_request) Successful in 24s
CI / Build (pull_request) Successful in 20s
Release / Create Release (push) Successful in 35s
feat(prdescribe): add configurable base branch flag
Introduce a new --base flag (default: "master") to specify the base branch for diff comparison in the PR describe command. Update logic to use this base in git diff commands and fallback to origin/base. Adjust no-changes message accordingly. Add tests for custom base and default behavior.
2026-03-04 18:11:28 +00:00

51 lines
1.4 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 init() {
prDescribeCmd.Flags().StringP("base", "b", "master", "Base branch to compare against")
}
func runPRDescribe(cmd *cobra.Command, args []string) {
base, _ := cmd.Flags().GetString("base")
diff, err := gitRun([]string{"diff", fmt.Sprintf("%s..HEAD", base), "--no-color"})
if err != nil || diff == "" {
diff, err = gitRun([]string{"diff", fmt.Sprintf("origin/%s..HEAD", base), "--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 %s/origin/%s.", base, base)
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)},
}
}