MCPcopy Create free account
hub / github.com/cli/cli / createFromTemplate

Function createFromTemplate

pkg/cmd/repo/create/create.go:439–531  ·  view source on GitHub ↗

create new repo on remote host from template repo

(opts *CreateOptions)

Source from the content-addressed store, hash-verified

437
438// create new repo on remote host from template repo
439func 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)

Callers 1

createRunFunction · 0.85

Calls 15

FromFullNameFunction · 0.92
NormalizeRepoNameFunction · 0.92
FullNameFunction · 0.92
FormatRemoteURLFunction · 0.92
interactiveRepoInfoFunction · 0.85
userAndOrgsFunction · 0.85
interactiveRepoTemplateFunction · 0.85
repoCreateFunction · 0.85
cloneWithRetryFunction · 0.85
ContainsMethod · 0.80
ColorSchemeMethod · 0.80
SuccessIconWithColorMethod · 0.80

Tested by

no test coverage detected