Compare commits

...

2 Commits

Author SHA1 Message Date
d92b88e90b Merge pull request 'Add --base Flag to prdescribe Command for Custom Base Branch Comparison' (#3) from fix/add_base_branch_to_prdescribe into master
All checks were successful
CI / Test (push) Successful in 32s
CI / Lint (push) Successful in 25s
CI / Build (push) Successful in 21s
Reviewed-on: #3
2026-03-04 18:16:54 +00:00
b1d3a445ec feat(prdescribe): add configurable base branch flag
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
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
2 changed files with 60 additions and 13 deletions

View File

@ -14,17 +14,23 @@ var prDescribeCmd = &cobra.Command{
Run: runPRDescribe, Run: runPRDescribe,
} }
func init() {
prDescribeCmd.Flags().StringP("base", "b", "master", "Base branch to compare against")
}
func runPRDescribe(cmd *cobra.Command, args []string) { func runPRDescribe(cmd *cobra.Command, args []string) {
diff, err := gitRun([]string{"diff", "main..HEAD", "--no-color"}) base, _ := cmd.Flags().GetString("base")
diff, err := gitRun([]string{"diff", fmt.Sprintf("%s..HEAD", base), "--no-color"})
if err != nil || diff == "" { if err != nil || diff == "" {
diff, err = gitRun([]string{"diff", "origin/main..HEAD", "--no-color"}) diff, err = gitRun([]string{"diff", fmt.Sprintf("origin/%s..HEAD", base), "--no-color"})
if err != nil { if err != nil {
color.Red("Failed to get branch diff: %v", err) color.Red("Failed to get branch diff: %v", err)
return return
} }
} }
if diff == "" { if diff == "" {
color.Yellow("No changes on this branch compared to main/origin/main.") color.Yellow("No changes on this branch compared to %s/origin/%s.", base, base)
return return
} }
modelFlag, _ := cmd.Flags().GetString("model") modelFlag, _ := cmd.Flags().GetString("model")

View File

@ -47,10 +47,11 @@ func withMockGit(fn func([]string) (string, error)) func() {
return func() { gitRun = orig } return func() { gitRun = orig }
} }
// testCmd returns a minimal cobra command with the model flag registered. // testCmd returns a minimal cobra command with common flags registered.
func testCmd() *cobra.Command { func testCmd() *cobra.Command {
c := &cobra.Command{} c := &cobra.Command{}
c.Flags().String("model", "", "") c.Flags().String("model", "", "")
c.Flags().String("base", "master", "")
return c return c
} }
@ -308,22 +309,62 @@ func TestRunPRDescribe(t *testing.T) {
} }
}) })
t.Run("second diff error — skips AI", func(t *testing.T) { t.Run("uses custom base branch", func(t *testing.T) {
mock := &mockStreamer{} mock := &mockStreamer{response: "PR description"}
defer withMockClient(mock)() defer withMockClient(mock)()
callCount := 0 var capturedArgs []string
defer withMockGit(func(args []string) (string, error) { defer withMockGit(func(args []string) (string, error) {
callCount++ capturedArgs = args
if callCount == 2 { return "diff content", nil
return "", errors.New("no remote") })()
cmd := testCmd()
if err := cmd.Flags().Set("base", "develop"); err != nil {
t.Fatal(err)
} }
return "", nil runPRDescribe(cmd, nil)
if mock.calls != 1 {
t.Errorf("expected 1 AI call, got %d", mock.calls)
}
// Expect "diff", "develop..HEAD", "--no-color"
expectedArg := "develop..HEAD"
found := false
for _, arg := range capturedArgs {
if arg == expectedArg {
found = true
break
}
}
if !found {
t.Errorf("expected arg %q not found in %v", expectedArg, capturedArgs)
}
})
t.Run("defaults to master", func(t *testing.T) {
mock := &mockStreamer{response: "PR description"}
defer withMockClient(mock)()
var capturedArgs []string
defer withMockGit(func(args []string) (string, error) {
capturedArgs = args
return "diff content", nil
})() })()
runPRDescribe(testCmd(), nil) runPRDescribe(testCmd(), nil)
if mock.calls != 0 { if mock.calls != 1 {
t.Errorf("expected 0 AI calls, got %d", mock.calls) t.Errorf("expected 1 AI call, got %d", mock.calls)
}
expectedArg := "master..HEAD"
found := false
for _, arg := range capturedArgs {
if arg == expectedArg {
found = true
break
}
}
if !found {
t.Errorf("expected arg %q not found in %v", expectedArg, capturedArgs)
} }
}) })
} }