Skip to content

Commit

Permalink
feat: allow initializing existing orbs #800 EXT-818]
Browse files Browse the repository at this point in the history
[EXT-818] allow initializing existing orbs
  • Loading branch information
KyleTryon authored Dec 5, 2022
2 parents 19bba9e + ff1a620 commit 802994b
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions cmd/orb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1196,11 +1196,30 @@ func initOrb(opts orbOptions) error {
Message: "Orb name",
Default: orbName,
}

orbExists := true

err = survey.AskOne(iprompt, &orbName)
if err != nil {
return errors.Wrap(err, "Unexpected error")
}

_, err = api.OrbInfo(opts.cl, namespace+"/"+orbName)
if err != nil {
orbExists = false
}

if orbExists {
mprompt := &survey.Confirm{
Message: fmt.Sprintf("Orb %s/%s already exists, would you like to continue?", namespace, orbName),
}
confirmation := false
err = survey.AskOne(mprompt, &confirmation)
if err != nil {
return errors.Wrap(err, "Orb already exists")
}
}

registryCategories, err := api.ListOrbCategories(opts.cl)
if err != nil {
return errors.Wrapf(err, "Failed to list orb categories")
Expand Down Expand Up @@ -1273,9 +1292,11 @@ func initOrb(opts orbOptions) error {
}()

if !gitAction {
_, err = api.CreateOrb(opts.cl, namespace, orbName, opts.private)
if err != nil {
return errors.Wrap(err, "Unable to create orb")
if !orbExists {
_, err = api.CreateOrb(opts.cl, namespace, orbName, opts.private)
if err != nil {
return errors.Wrap(err, "Unable to create orb")
}
}
for _, v := range categories {
err = api.AddOrRemoveOrbCategorization(opts.cl, namespace, orbName, v, api.Add)
Expand Down Expand Up @@ -1410,9 +1431,11 @@ func initOrb(opts orbOptions) error {
}

// Push a dev version of the orb.
_, err = api.CreateOrb(opts.cl, namespace, orbName, opts.private)
if err != nil {
return errors.Wrap(err, "Unable to create orb")
if !orbExists {
_, err = api.CreateOrb(opts.cl, namespace, orbName, opts.private)
if err != nil {
return errors.Wrap(err, "Unable to create orb")
}
}
for _, v := range categories {
err = api.AddOrRemoveOrbCategorization(opts.cl, namespace, orbName, v, api.Add)
Expand Down

0 comments on commit 802994b

Please sign in to comment.