feat: automatically prompt for default remote in browse and PR create commands#13008
feat: automatically prompt for default remote in browse and PR create commands#13008trueberryless wants to merge 1 commit intocli:trunkfrom
Conversation
…r pr create commands
|
Thanks for your pull request! Unfortunately, it doesn't meet the minimum requirements for review:
Please update your PR to address the above. Requirements:
This PR will be automatically closed in 7 days if these requirements are not met. |
There was a problem hiding this comment.
Pull request overview
This PR updates repository base-resolution behavior so gh browse and gh pr create can automatically prompt the user to choose and persist a default remote repository when none is configured, reducing the need to manually run gh repo set-default.
Changes:
- Extends
ResolvedRemotes.BaseRepoto accept a prompter and git client so it can prompt for a default repo and write theremote.<name>.gh-resolvedconfig. - Updates
gh pr createto pass the prompter and git client into base-repo resolution. - Updates the factory’s
SmartBaseRepoFuncto pass the prompter and git client, enabling this behavior across commands that rely on it (includinggh browse).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
context/context.go |
Adds interactive prompting + git config persistence for default remote selection during base repo resolution. |
pkg/cmd/pr/create/create.go |
Wires prompter + git client into base repo resolution for PR create flows. |
pkg/cmd/factory/default.go |
Wires prompter + git client into SmartBaseRepoFunc to enable prompting in commands using factory base repo resolution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| var baseRepo *api.Repository | ||
| if br, err := resolvedRemotes.BaseRepo(opts.IO); err == nil { | ||
| if br, err := resolvedRemotes.BaseRepo(opts.IO, opts.Prompter.(prompter.Prompter), opts.GitClient); err == nil { |
There was a problem hiding this comment.
The type assertion opts.Prompter.(prompter.Prompter) can panic at runtime if CreateOptions.Prompter is nil or is an implementation that satisfies shared.Prompt but not internal/prompter.Prompter. Consider changing ResolvedRemotes.BaseRepo to accept a smaller interface (e.g., just Select) or using a comma-ok assertion and falling back to nil/an error when the prompter isn’t compatible.
| if br, err := resolvedRemotes.BaseRepo(opts.IO, opts.Prompter.(prompter.Prompter), opts.GitClient); err == nil { | |
| var p prompter.Prompter | |
| if pp, ok := opts.Prompter.(prompter.Prompter); ok { | |
| p = pp | |
| } | |
| if br, err := resolvedRemotes.BaseRepo(opts.IO, p, opts.GitClient); err == nil { |
| return nil, err | ||
| } | ||
| baseRepo, err := repoContext.BaseRepo(opts.IO) | ||
| baseRepo, err := repoContext.BaseRepo(opts.IO, opts.Prompter.(prompter.Prompter), opts.GitClient) |
There was a problem hiding this comment.
Same runtime-panic risk here from opts.Prompter.(prompter.Prompter). Prefer passing a narrower prompt interface into BaseRepo or guarding the assertion with a comma-ok check.
| baseRepo, err := repoContext.BaseRepo(opts.IO, opts.Prompter.(prompter.Prompter), opts.GitClient) | |
| prompterImpl, ok := opts.Prompter.(prompter.Prompter) | |
| if !ok { | |
| return nil, fmt.Errorf("prompter does not implement prompter.Prompter") | |
| } | |
| baseRepo, err := repoContext.BaseRepo(opts.IO, prompterImpl, opts.GitClient) |
|
|
||
| return selectedRepo, nil | ||
| } | ||
|
|
There was a problem hiding this comment.
When multiple repos are discovered and io.CanPrompt() is true, this now silently falls back to r.remotes[0] if either prompter or gitClient is nil. Previously this case produced a clear error instructing the user to run gh repo set-default, which avoids surprising behavior (opening/operating on the wrong repo) and makes it clear why selection wasn’t possible. Consider restoring an error (and possibly the explanatory message) when prompting/persisting the selection isn’t available.
| if io.CanPrompt() { | |
| return nil, errors.New("could not prompt to select a base repository. To avoid operating on the wrong repository, run `gh repo set-default` to choose a default") | |
| } |
Description
This PR implements new interactions when running the
gh browseorgh pr createcommands, which will ask the user which remote repository should be set as default if it is not set already. Previously, the output just explained that the default repo has to be set with thegh repo set-defaultcommand and the user had to manually copy and paste the command into the command line. I find it pretty useful, if this would happen automatically, as it would improve my usual workflow.Related
gh browsecommand should automatically rungh repo set-defaultif not yet configured #13006