Skip to content

Commit 99372f0

Browse files
committed
[Refactor] Add variadic argument to repoCreate to support templates
1 parent 2886dd9 commit 99372f0

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

pkg/cmd/repo/create/create.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
7878
}
7979

8080
if opts.Template != "" && (opts.Homepage != "" || opts.Team != "" || !opts.EnableIssues || !opts.EnableWiki) {
81-
return &cmdutil.FlagError{Err: errors.New(`the '--template' option is not supported with '--homepage, --team, --enable-issues or --enable-wiki'`)}
81+
return &cmdutil.FlagError{Err: errors.New(`The '--template' option is not supported with '--homepage, --team, --enable-issues or --enable-wiki'`)}
8282
}
8383

8484
return createRun(opts)
@@ -173,8 +173,7 @@ func createRun(opts *CreateOptions) error {
173173
}
174174
}
175175

176-
// find template ID
177-
176+
// Find template repo ID
178177
if opts.Template != "" {
179178
httpClient, err := opts.HttpClient()
180179
if err != nil {
@@ -210,7 +209,6 @@ func createRun(opts *CreateOptions) error {
210209
Visibility: visibility,
211210
OwnerID: repoToCreate.RepoOwner(),
212211
TeamID: opts.Team,
213-
RepositoryID: opts.Template,
214212
Description: opts.Description,
215213
HomepageURL: opts.Homepage,
216214
HasIssuesEnabled: opts.EnableIssues,
@@ -231,7 +229,7 @@ func createRun(opts *CreateOptions) error {
231229
}
232230

233231
if opts.ConfirmSubmit {
234-
repo, err := repoCreate(httpClient, repoToCreate.RepoHost(), input)
232+
repo, err := repoCreate(httpClient, repoToCreate.RepoHost(), input, opts.Template)
235233
if err != nil {
236234
return err
237235
}

pkg/cmd/repo/create/create_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ func TestRepoCreate_template(t *testing.T) {
379379
}
380380

381381
if len(reg.Requests) != 3 {
382-
t.Fatalf("expected 3 HTTP request, got %d", len(reg.Requests))
382+
t.Fatalf("expected 3 HTTP requests, got %d", len(reg.Requests))
383383
}
384384

385385
bodyBytes, _ := ioutil.ReadAll(reg.Requests[2].Body)

pkg/cmd/repo/create/http.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ type repoCreateInput struct {
1414
HomepageURL string `json:"homepageUrl,omitempty"`
1515
Description string `json:"description,omitempty"`
1616

17-
RepositoryID string `json:"repositoryId,omitempty"`
18-
1917
OwnerID string `json:"ownerId,omitempty"`
2018
TeamID string `json:"teamId,omitempty"`
2119

@@ -33,7 +31,7 @@ type repoTemplateInput struct {
3331
}
3432

3533
// repoCreate creates a new GitHub repository
36-
func repoCreate(client *http.Client, hostname string, input repoCreateInput) (*api.Repository, error) {
34+
func repoCreate(client *http.Client, hostname string, input repoCreateInput, templateRepositoryID string) (*api.Repository, error) {
3735
apiClient := api.NewClientFromHTTP(client)
3836

3937
if input.TeamID != "" {
@@ -51,7 +49,7 @@ func repoCreate(client *http.Client, hostname string, input repoCreateInput) (*a
5149
input.OwnerID = orgID
5250
}
5351

54-
if input.RepositoryID != "" {
52+
if templateRepositoryID != "" {
5553
var response struct {
5654
CloneTemplateRepository struct {
5755
Repository api.Repository
@@ -70,7 +68,7 @@ func repoCreate(client *http.Client, hostname string, input repoCreateInput) (*a
7068
Name: input.Name,
7169
Visibility: input.Visibility,
7270
OwnerID: input.OwnerID,
73-
RepositoryID: input.RepositoryID,
71+
RepositoryID: templateRepositoryID,
7472
}
7573

7674
variables := map[string]interface{}{

pkg/cmd/repo/create/http_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func Test_RepoCreate(t *testing.T) {
2121
HomepageURL: "http://example.com",
2222
}
2323

24-
_, err := repoCreate(httpClient, "github.com", input)
24+
_, err := repoCreate(httpClient, "github.com", input, "")
2525
if err != nil {
2626
t.Fatalf("unexpected error: %v", err)
2727
}

0 commit comments

Comments
 (0)