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