Update the git diff command to first attempt using the remote origin/base branch, as it is more likely to be up-to-date for pull requests. Fall back to the local base branch if the remote diff fails or is empty.
58 lines
1.7 KiB
Go
58 lines
1.7 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/fatih/color"
|
|
"github.com/spf13/cobra"
|
|
"gmgauthier.com/grokkit/config"
|
|
"gmgauthier.com/grokkit/internal/git"
|
|
)
|
|
|
|
// gitDiff is the mockable entry point (exactly like gitRun used elsewhere).
|
|
var gitDiff = git.Diff
|
|
|
|
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 (default: master)")
|
|
}
|
|
|
|
func runPRDescribe(cmd *cobra.Command, _ []string) {
|
|
base, _ := cmd.Flags().GetString("base")
|
|
|
|
// Prefer remote (more likely up-to-date for PRs), fallback to local.
|
|
diff, err := gitDiff([]string{"diff", fmt.Sprintf("origin/%s..HEAD", base), "--no-color"})
|
|
if err != nil || strings.TrimSpace(diff) == "" {
|
|
diff, err = gitDiff([]string{"diff", fmt.Sprintf("%s..HEAD", base), "--no-color"})
|
|
if err != nil {
|
|
color.Red("Failed to get branch diff: %v", err)
|
|
return
|
|
}
|
|
}
|
|
if strings.TrimSpace(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 (base=%s)...", base)
|
|
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)},
|
|
}
|
|
}
|