Skip to content

feat: automatically prompt for default remote in browse and PR create commands#13008

Open
trueberryless wants to merge 1 commit intocli:trunkfrom
trueberryless:feat/select-default-with-browse-command
Open

feat: automatically prompt for default remote in browse and PR create commands#13008
trueberryless wants to merge 1 commit intocli:trunkfrom
trueberryless:feat/select-default-with-browse-command

Conversation

@trueberryless
Copy link
Copy Markdown

Description

This PR implements new interactions when running the gh browse or gh pr create commands, 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 the gh repo set-default command 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

Copilot AI review requested due to automatic review settings March 23, 2026 17:43
@trueberryless trueberryless requested a review from a team as a code owner March 23, 2026 17:43
@github-actions github-actions bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed unmet-requirements and removed needs-triage needs to be reviewed labels Mar 23, 2026
@github-actions
Copy link
Copy Markdown

Thanks for your pull request! Unfortunately, it doesn't meet the minimum requirements for review:

  • None of the referenced issues have the help wanted label

Please update your PR to address the above. Requirements:

  1. Include a detailed description of what this PR does
  2. Link to an issue with the help wanted label (use Fixes #123 or Closes #123 if it resolves the issue)

This PR will be automatically closed in 7 days if these requirements are not met.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.BaseRepo to accept a prompter and git client so it can prompt for a default repo and write the remote.<name>.gh-resolved config.
  • Updates gh pr create to pass the prompter and git client into base-repo resolution.
  • Updates the factory’s SmartBaseRepoFunc to pass the prompter and git client, enabling this behavior across commands that rely on it (including gh 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 {
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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 {

Copilot uses AI. Check for mistakes.
return nil, err
}
baseRepo, err := repoContext.BaseRepo(opts.IO)
baseRepo, err := repoContext.BaseRepo(opts.IO, opts.Prompter.(prompter.Prompter), opts.GitClient)
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.

return selectedRepo, nil
}

Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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")
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team unmet-requirements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh browse command should automatically run gh repo set-default if not yet configured

2 participants