diff --git a/pkg/cmd/repo/create/create.go b/pkg/cmd/repo/create/create.go index 2ac91eb55..fc53b460e 100644 --- a/pkg/cmd/repo/create/create.go +++ b/pkg/cmd/repo/create/create.go @@ -78,7 +78,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co } if opts.Template != "" && (opts.Homepage != "" || opts.Team != "" || !opts.EnableIssues || !opts.EnableWiki) { - return &cmdutil.FlagError{Err: errors.New(`the '--template' option is not supported with '--homepage, --team, --enable-issues or --enable-wiki'`)} + return &cmdutil.FlagError{Err: errors.New(`The '--template' option is not supported with '--homepage, --team, --enable-issues or --enable-wiki'`)} } return createRun(opts) @@ -173,8 +173,7 @@ func createRun(opts *CreateOptions) error { } } - // find template ID - + // Find template repo ID if opts.Template != "" { httpClient, err := opts.HttpClient() if err != nil { @@ -210,7 +209,6 @@ func createRun(opts *CreateOptions) error { Visibility: visibility, OwnerID: repoToCreate.RepoOwner(), TeamID: opts.Team, - RepositoryID: opts.Template, Description: opts.Description, HomepageURL: opts.Homepage, HasIssuesEnabled: opts.EnableIssues, @@ -231,7 +229,7 @@ func createRun(opts *CreateOptions) error { } if opts.ConfirmSubmit { - repo, err := repoCreate(httpClient, repoToCreate.RepoHost(), input) + repo, err := repoCreate(httpClient, repoToCreate.RepoHost(), input, opts.Template) if err != nil { return err } diff --git a/pkg/cmd/repo/create/create_test.go b/pkg/cmd/repo/create/create_test.go index f3de15c5a..8eb1a2423 100644 --- a/pkg/cmd/repo/create/create_test.go +++ b/pkg/cmd/repo/create/create_test.go @@ -379,7 +379,7 @@ func TestRepoCreate_template(t *testing.T) { } if len(reg.Requests) != 3 { - t.Fatalf("expected 3 HTTP request, got %d", len(reg.Requests)) + t.Fatalf("expected 3 HTTP requests, got %d", len(reg.Requests)) } bodyBytes, _ := ioutil.ReadAll(reg.Requests[2].Body) diff --git a/pkg/cmd/repo/create/http.go b/pkg/cmd/repo/create/http.go index e8d3f29b1..70df0dfb7 100644 --- a/pkg/cmd/repo/create/http.go +++ b/pkg/cmd/repo/create/http.go @@ -14,8 +14,6 @@ type repoCreateInput struct { HomepageURL string `json:"homepageUrl,omitempty"` Description string `json:"description,omitempty"` - RepositoryID string `json:"repositoryId,omitempty"` - OwnerID string `json:"ownerId,omitempty"` TeamID string `json:"teamId,omitempty"` @@ -33,7 +31,7 @@ type repoTemplateInput struct { } // repoCreate creates a new GitHub repository -func repoCreate(client *http.Client, hostname string, input repoCreateInput) (*api.Repository, error) { +func repoCreate(client *http.Client, hostname string, input repoCreateInput, templateRepositoryID string) (*api.Repository, error) { apiClient := api.NewClientFromHTTP(client) if input.TeamID != "" { @@ -51,7 +49,7 @@ func repoCreate(client *http.Client, hostname string, input repoCreateInput) (*a input.OwnerID = orgID } - if input.RepositoryID != "" { + if templateRepositoryID != "" { var response struct { CloneTemplateRepository struct { Repository api.Repository @@ -70,7 +68,7 @@ func repoCreate(client *http.Client, hostname string, input repoCreateInput) (*a Name: input.Name, Visibility: input.Visibility, OwnerID: input.OwnerID, - RepositoryID: input.RepositoryID, + RepositoryID: templateRepositoryID, } variables := map[string]interface{}{ diff --git a/pkg/cmd/repo/create/http_test.go b/pkg/cmd/repo/create/http_test.go index 4b764572c..c8e2e7a2a 100644 --- a/pkg/cmd/repo/create/http_test.go +++ b/pkg/cmd/repo/create/http_test.go @@ -21,7 +21,7 @@ func Test_RepoCreate(t *testing.T) { HomepageURL: "http://example.com", } - _, err := repoCreate(httpClient, "github.com", input) + _, err := repoCreate(httpClient, "github.com", input, "") if err != nil { t.Fatalf("unexpected error: %v", err) }