create new repo on remote host from template repo
(opts *CreateOptions)
| 437 | |
| 438 | // create new repo on remote host from template repo |
| 439 | func createFromTemplate(opts *CreateOptions) error { |
| 440 | httpClient, err := opts.HttpClient() |
| 441 | if err != nil { |
| 442 | return err |
| 443 | } |
| 444 | |
| 445 | cfg, err := opts.Config() |
| 446 | if err != nil { |
| 447 | return err |
| 448 | } |
| 449 | |
| 450 | host, _ := cfg.Authentication().DefaultHost() |
| 451 | |
| 452 | opts.Name, opts.Description, opts.Visibility, err = interactiveRepoInfo(httpClient, host, opts.Prompter, "") |
| 453 | if err != nil { |
| 454 | return err |
| 455 | } |
| 456 | |
| 457 | if !strings.Contains(opts.Name, "/") { |
| 458 | username, _, err := userAndOrgs(httpClient, host) |
| 459 | if err != nil { |
| 460 | return err |
| 461 | } |
| 462 | opts.Name = fmt.Sprintf("%s/%s", username, opts.Name) |
| 463 | } |
| 464 | repoToCreate, err := ghrepo.FromFullName(opts.Name) |
| 465 | if err != nil { |
| 466 | return fmt.Errorf("argument error: %w", err) |
| 467 | } |
| 468 | |
| 469 | templateRepo, err := interactiveRepoTemplate(httpClient, host, repoToCreate.RepoOwner(), opts.Prompter) |
| 470 | if err != nil { |
| 471 | return err |
| 472 | } |
| 473 | input := repoCreateInput{ |
| 474 | Name: repoToCreate.RepoName(), |
| 475 | Visibility: opts.Visibility, |
| 476 | OwnerLogin: repoToCreate.RepoOwner(), |
| 477 | TeamSlug: opts.Team, |
| 478 | Description: opts.Description, |
| 479 | HomepageURL: opts.Homepage, |
| 480 | HasIssuesEnabled: !opts.DisableIssues, |
| 481 | HasWikiEnabled: !opts.DisableWiki, |
| 482 | GitIgnoreTemplate: opts.GitIgnoreTemplate, |
| 483 | LicenseTemplate: opts.LicenseTemplate, |
| 484 | IncludeAllBranches: opts.IncludeAllBranches, |
| 485 | InitReadme: opts.AddReadme, |
| 486 | TemplateRepositoryID: templateRepo.ID, |
| 487 | } |
| 488 | templateRepoMainBranch := templateRepo.DefaultBranchRef.Name |
| 489 | |
| 490 | targetRepo := shared.NormalizeRepoName(opts.Name) |
| 491 | if idx := strings.IndexRune(opts.Name, '/'); idx > 0 { |
| 492 | targetRepo = opts.Name[0:idx+1] + shared.NormalizeRepoName(opts.Name[idx+1:]) |
| 493 | } |
| 494 | confirmed, err := opts.Prompter.Confirm( |
| 495 | fmt.Sprintf(`This will create "%s" as a %s repository on %s. Continue?`, targetRepo, strings.ToLower(opts.Visibility), host), |
| 496 | true) |
no test coverage detected