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

Function createFromScratch

pkg/cmd/repo/create/create.go:296–436  ·  view source on GitHub ↗

create new repo on remote host

(opts *CreateOptions)

Source from the content-addressed store, hash-verified

294
295// create new repo on remote host
296func createFromScratch(opts *CreateOptions) error {
297 httpClient, err := opts.HttpClient()
298 if err != nil {
299 return err
300 }
301
302 var repoToCreate ghrepo.Interface
303 cfg, err := opts.Config()
304 if err != nil {
305 return err
306 }
307
308 host, _ := cfg.Authentication().DefaultHost()
309
310 if opts.Interactive {
311 opts.Name, opts.Description, opts.Visibility, err = interactiveRepoInfo(httpClient, host, opts.Prompter, "")
312 if err != nil {
313 return err
314 }
315 opts.AddReadme, err = opts.Prompter.Confirm("Would you like to add a README file?", false)
316 if err != nil {
317 return err
318 }
319 opts.GitIgnoreTemplate, err = interactiveGitIgnore(httpClient, host, opts.Prompter)
320 if err != nil {
321 return err
322 }
323 opts.LicenseTemplate, err = interactiveLicense(httpClient, host, opts.Prompter)
324 if err != nil {
325 return err
326 }
327
328 targetRepo := shared.NormalizeRepoName(opts.Name)
329 if idx := strings.IndexRune(opts.Name, '/'); idx > 0 {
330 targetRepo = opts.Name[0:idx+1] + shared.NormalizeRepoName(opts.Name[idx+1:])
331 }
332 confirmed, err := opts.Prompter.Confirm(
333 fmt.Sprintf(`This will create "%s" as a %s repository on %s. Continue?`, targetRepo, strings.ToLower(opts.Visibility), host),
334 true)
335 if err != nil {
336 return err
337 } else if !confirmed {
338 return cmdutil.CancelError
339 }
340 }
341
342 if strings.Contains(opts.Name, "/") {
343 var err error
344 repoToCreate, err = ghrepo.FromFullName(opts.Name)
345 if err != nil {
346 return fmt.Errorf("argument error: %w", err)
347 }
348 } else {
349 repoToCreate = ghrepo.NewWithHost("", opts.Name, host)
350 }
351
352 input := repoCreateInput{
353 Name: repoToCreate.RepoName(),

Callers 1

createRunFunction · 0.85

Calls 15

RepoNameMethod · 0.95
RepoOwnerMethod · 0.95
RepoHostMethod · 0.95
NormalizeRepoNameFunction · 0.92
FromFullNameFunction · 0.92
NewWithHostFunction · 0.92
NewClientFromHTTPFunction · 0.92
CurrentLoginNameFunction · 0.92
GitHubRepoFunction · 0.92
FullNameFunction · 0.92
FormatRemoteURLFunction · 0.92
interactiveRepoInfoFunction · 0.85

Tested by

no test coverage detected