diff --git a/pkg/cmd/repo/create/create.go b/pkg/cmd/repo/create/create.go index 7b9ec70d2..e4776c4e4 100644 --- a/pkg/cmd/repo/create/create.go +++ b/pkg/cmd/repo/create/create.go @@ -221,21 +221,23 @@ func createRun(opts *CreateOptions) error { return err } - // GitIgnore and License templates not added when a template repository is passed. - if gitIgnoreTemplate == "" && opts.Template == "" && opts.IO.CanPrompt() { - gt, err := interactiveGitIgnore(api.NewClientFromHTTP(httpClient), host) - if err != nil { - return err + // GitIgnore and License templates not added when a template repository + // is passed, or when the confirm flag is set. + if opts.Template == "" && opts.IO.CanPrompt() && !opts.ConfirmSubmit { + if gitIgnoreTemplate == "" { + gt, err := interactiveGitIgnore(api.NewClientFromHTTP(httpClient), host) + if err != nil { + return err + } + gitIgnoreTemplate = gt } - gitIgnoreTemplate = gt - } - - if repoLicenseTemplate == "" && opts.Template == "" && opts.IO.CanPrompt() { - lt, err := interactiveLicense(api.NewClientFromHTTP(httpClient), host) - if err != nil { - return err + if repoLicenseTemplate == "" { + lt, err := interactiveLicense(api.NewClientFromHTTP(httpClient), host) + if err != nil { + return err + } + repoLicenseTemplate = lt } - repoLicenseTemplate = lt } } diff --git a/pkg/cmd/repo/create/create_test.go b/pkg/cmd/repo/create/create_test.go index b74bbe8b2..70361a2ed 100644 --- a/pkg/cmd/repo/create/create_test.go +++ b/pkg/cmd/repo/create/create_test.go @@ -817,3 +817,64 @@ func TestRepoCreate_WithGitIgnore_Org(t *testing.T) { t.Errorf("expected %q, got %q", "OWNERID", ownerId) } } + +func TestRepoCreate_WithConfirmFlag(t *testing.T) { + cs, cmdTeardown := run.Stub() + defer cmdTeardown(t) + + cs.Register(`git remote add -f origin https://github\.com/OWNER/REPO\.git`, 0, "") + cs.Register(`git rev-parse --show-toplevel`, 0, "") + + reg := &httpmock.Registry{} + + reg.Register( + httpmock.GraphQL(`mutation RepositoryCreate\b`), + httpmock.StringResponse(` + { "data": { "createRepository": { + "repository": { + "id": "REPOID", + "url": "https://github.com/OWNER/REPO", + "name": "REPO", + "owner": { + "login": "OWNER" + } + } + } } }`), + ) + + reg.Register( + httpmock.REST("GET", "users/OWNER"), + httpmock.StringResponse(`{ "node_id": "OWNERID" }`), + ) + + httpClient := &http.Client{Transport: reg} + + in := "OWNER/REPO --confirm --private" + output, err := runCommand(httpClient, in, true) + if err != nil { + t.Errorf("error running command `repo create %v`: %v", in, err) + } + + assert.Equal(t, "", output.String()) + assert.Equal(t, "āœ“ Created repository OWNER/REPO on GitHub\nāœ“ Added remote https://github.com/OWNER/REPO.git\n", output.Stderr()) + + var reqBody struct { + Query string + Variables struct { + Input map[string]interface{} + } + } + + if len(reg.Requests) != 2 { + t.Fatalf("expected 2 HTTP request, got %d", len(reg.Requests)) + } + + bodyBytes, _ := ioutil.ReadAll(reg.Requests[1].Body) + _ = json.Unmarshal(bodyBytes, &reqBody) + if repoName := reqBody.Variables.Input["name"].(string); repoName != "REPO" { + t.Errorf("expected %q, got %q", "REPO", repoName) + } + if repoVisibility := reqBody.Variables.Input["visibility"].(string); repoVisibility != "PRIVATE" { + t.Errorf("expected %q, got %q", "PRIVATE", repoVisibility) + } +}