MCPcopy
hub / github.com/cli/cli / createFromTemplate

Function createFromTemplate

pkg/cmd/repo/create/create.go:438–530  ·  view source on GitHub ↗

create new repo on remote host from template repo

(opts *CreateOptions)

Source from the content-addressed store, hash-verified

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