Teach gh cs create to use current repo as default (#6596)
Co-authored-by: Mislav Marohnić <mislav@github.com>
This commit is contained in:
parent
626c639df5
commit
78fb90956c
11 changed files with 26 additions and 9 deletions
|
|
@ -97,7 +97,7 @@ func TestPendingOperationDisallowsCode(t *testing.T) {
|
|||
|
||||
func testingCodeApp() *App {
|
||||
ios, _, _, _ := iostreams.Test()
|
||||
return NewApp(ios, nil, testCodeApiMock(), nil)
|
||||
return NewApp(ios, nil, testCodeApiMock(), nil, nil)
|
||||
}
|
||||
|
||||
func testCodeApiMock() *apiClientMock {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/AlecAivazis/survey/v2/terminal"
|
||||
clicontext "github.com/cli/cli/v2/context"
|
||||
"github.com/cli/cli/v2/internal/browser"
|
||||
"github.com/cli/cli/v2/internal/codespaces"
|
||||
"github.com/cli/cli/v2/internal/codespaces/api"
|
||||
|
|
@ -32,9 +33,10 @@ type App struct {
|
|||
errLogger *log.Logger
|
||||
executable executable
|
||||
browser browser.Browser
|
||||
remotes func() (clicontext.Remotes, error)
|
||||
}
|
||||
|
||||
func NewApp(io *iostreams.IOStreams, exe executable, apiClient apiClient, browser browser.Browser) *App {
|
||||
func NewApp(io *iostreams.IOStreams, exe executable, apiClient apiClient, browser browser.Browser, remotes func() (clicontext.Remotes, error)) *App {
|
||||
errLogger := log.New(io.ErrOut, "", 0)
|
||||
|
||||
return &App{
|
||||
|
|
@ -43,6 +45,7 @@ func NewApp(io *iostreams.IOStreams, exe executable, apiClient apiClient, browse
|
|||
errLogger: errLogger,
|
||||
executable: exe,
|
||||
browser: browser,
|
||||
remotes: remotes,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/cli/cli/v2/internal/codespaces"
|
||||
"github.com/cli/cli/v2/internal/codespaces/api"
|
||||
"github.com/cli/cli/v2/internal/ghrepo"
|
||||
"github.com/cli/cli/v2/internal/text"
|
||||
"github.com/cli/cli/v2/pkg/cmdutil"
|
||||
"github.com/spf13/cobra"
|
||||
|
|
@ -119,12 +120,24 @@ func (a *App) Create(ctx context.Context, opts createOptions) error {
|
|||
|
||||
promptForRepoAndBranch := userInputs.Repository == ""
|
||||
if promptForRepoAndBranch {
|
||||
var defaultRepo string
|
||||
if remotes, _ := a.remotes(); remotes != nil {
|
||||
if defaultRemote, _ := remotes.ResolvedRemote(); defaultRemote != nil {
|
||||
// this is a remote explicitly chosen via `repo set-default`
|
||||
defaultRepo = ghrepo.FullName(defaultRemote)
|
||||
} else if len(remotes) > 0 {
|
||||
// as a fallback, just pick the first remote
|
||||
defaultRepo = ghrepo.FullName(remotes[0])
|
||||
}
|
||||
}
|
||||
|
||||
repoQuestions := []*survey.Question{
|
||||
{
|
||||
Name: "repository",
|
||||
Prompt: &survey.Input{
|
||||
Message: "Repository:",
|
||||
Help: "Search for repos by name. To search within an org or user, or to see private repos, enter at least ':user/'.",
|
||||
Default: defaultRepo,
|
||||
Suggest: func(toComplete string) []string {
|
||||
return getRepoSuggestions(ctx, a.apiClient, toComplete)
|
||||
},
|
||||
|
|
|
|||
|
|
@ -266,7 +266,7 @@ func TestDelete(t *testing.T) {
|
|||
ios, _, stdout, stderr := iostreams.Test()
|
||||
ios.SetStdinTTY(true)
|
||||
ios.SetStdoutTTY(true)
|
||||
app := NewApp(ios, nil, apiMock, nil)
|
||||
app := NewApp(ios, nil, apiMock, nil, nil)
|
||||
err := app.Delete(context.Background(), opts)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("delete() error = %v, wantErr %v", err, tt.wantErr)
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ func TestEdit(t *testing.T) {
|
|||
}
|
||||
|
||||
ios, _, stdout, stderr := iostreams.Test()
|
||||
a := NewApp(ios, nil, apiMock, nil)
|
||||
a := NewApp(ios, nil, apiMock, nil, nil)
|
||||
|
||||
var err error
|
||||
if tt.cliArgs == nil {
|
||||
|
|
|
|||
|
|
@ -36,5 +36,5 @@ func testingLogsApp() *App {
|
|||
}
|
||||
|
||||
ios, _, _, _ := iostreams.Test()
|
||||
return NewApp(ios, nil, apiMock, nil)
|
||||
return NewApp(ios, nil, apiMock, nil, nil)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -263,5 +263,5 @@ func testingPortsApp() *App {
|
|||
|
||||
ios, _, _, _ := iostreams.Test()
|
||||
|
||||
return NewApp(ios, nil, apiMock, nil)
|
||||
return NewApp(ios, nil, apiMock, nil, nil)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,5 +32,5 @@ func testingRebuildApp(mockCodespace api.Codespace) *App {
|
|||
}
|
||||
|
||||
ios, _, _, _ := iostreams.Test()
|
||||
return NewApp(ios, nil, apiMock, nil)
|
||||
return NewApp(ios, nil, apiMock, nil, nil)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ func TestApp_Select(t *testing.T) {
|
|||
ios, _, stdout, stderr := iostreams.Test()
|
||||
ios.SetStdinTTY(true)
|
||||
ios.SetStdoutTTY(true)
|
||||
a := NewApp(ios, nil, testSelectApiMock(), nil)
|
||||
a := NewApp(ios, nil, testSelectApiMock(), nil, nil)
|
||||
|
||||
opts := selectOptions{}
|
||||
if tt.outputToFile {
|
||||
|
|
|
|||
|
|
@ -278,5 +278,5 @@ func testingSSHApp() *App {
|
|||
}
|
||||
|
||||
ios, _, _, _ := iostreams.Test()
|
||||
return NewApp(ios, nil, apiMock, nil)
|
||||
return NewApp(ios, nil, apiMock, nil, nil)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -167,6 +167,7 @@ func newCodespaceCmd(f *cmdutil.Factory) *cobra.Command {
|
|||
&lazyLoadedHTTPClient{factory: f},
|
||||
),
|
||||
f.Browser,
|
||||
f.Remotes,
|
||||
)
|
||||
cmd := codespaceCmd.NewRootCmd(app)
|
||||
cmd.Use = "codespace"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue