MCPcopy Create free account
hub / github.com/Scalingo/cli / interactiveCreate

Function interactiveCreate

cmd/integration_link.go:458–549  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

456)
457
458func interactiveCreate(ctx context.Context) (scalingo.SCMRepoLinkCreateParams, error) {
459 var params scalingo.SCMRepoLinkCreateParams
460 if config.C.DisableInteractive {
461 return params, errors.New(ctx, "need at least one integration link parameter")
462 }
463 qs := []*survey.Question{
464 {
465 Name: "branch",
466 Prompt: &survey.Input{Message: "Branch to auto-deploy (empty to disable):"},
467 },
468 {
469 Name: "auto-review-apps",
470 Prompt: &survey.Confirm{
471 Message: "Automatically deploy review apps:",
472 Default: false,
473 },
474 },
475 }
476
477 answers := struct {
478 Branch string
479 AutoReviewApps bool `survey:"auto-review-apps"`
480 }{}
481 err := survey.Ask(qs, &answers)
482 if err != nil {
483 return params, errors.Wrapf(ctx, err, "error enquiring about branch and automatic review apps deployment")
484 }
485
486 if answers.Branch != "" {
487 params.Branch = &answers.Branch
488 params.AutoDeployEnabled = utils.BoolPtr(true)
489 }
490 if !answers.AutoReviewApps {
491 return params, nil
492 }
493
494 params.DeployReviewAppsEnabled = utils.BoolPtr(true)
495
496 destroyOnClose := true
497 err = survey.AskOne(&survey.Confirm{
498 Message: "Automatically destroy review apps when the pull/merge request is closed:",
499 Default: destroyOnClose,
500 }, &destroyOnClose, nil)
501 if err != nil {
502 return params, errors.Wrapf(ctx, err, "error enquiring about destroy on close")
503 }
504 params.DestroyOnCloseEnabled = &destroyOnClose
505 if destroyOnClose {
506 answerHoursBeforeDestroyOnClose := "0"
507 err = survey.AskOne(&survey.Input{
508 Message: "Hours before automatically destroying the review apps:",
509 Default: "0",
510 }, &answerHoursBeforeDestroyOnClose, survey.WithValidator(validateHoursBeforeDelete(ctx)))
511 if err != nil {
512 return params, errors.Wrapf(ctx, err, "error enquiring about review apps destroy delay")
513 }
514 hoursBeforeDestroyOnClose64, _ := strconv.ParseUint(answerHoursBeforeDestroyOnClose, 10, 32)
515 hoursBeforeDestroyOnClose := uint(hoursBeforeDestroyOnClose64)

Callers 1

Calls 3

BoolPtrFunction · 0.92

Tested by

no test coverage detected