Skip to content

Commit

Permalink
Orb init improvements / bugfixes (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Simmer authored Mar 9, 2021
1 parent 84d803e commit 272a716
Showing 1 changed file with 51 additions and 3 deletions.
54 changes: 51 additions & 3 deletions cmd/orb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ func initOrb(opts orbOptions) error {
if err != nil {
return errors.Wrap(err, "Unexpected error")
}
tags := []orbProtectTemplateRelease{}
var tags []orbProtectTemplateRelease
err = json.Unmarshal(body, &tags)
if err != nil {
return errors.Wrap(err, "Unexpected error")
Expand Down Expand Up @@ -1185,6 +1185,29 @@ func initOrb(opts orbOptions) error {
return errors.Wrap(err, "Unexpected error")
}

registryCategories, err := api.ListOrbCategories(opts.cl)
if err != nil {
return errors.Wrapf(err, "Failed to list orb categories")
}
c := func() []string {
var x []string
for _, v := range registryCategories.OrbCategories {
x = append(x, v.Name)
}

return x
}()

var categories []string
cPrompt := &survey.MultiSelect{
Message: "What categories will this orb belong to?",
Options: c,
}
err = survey.AskOne(cPrompt, &categories)
if err != nil {
return err
}

createContext := 0
prompt = &survey.Select{
Message: "Automatically set up a publishing context for your orb?",
Expand Down Expand Up @@ -1234,13 +1257,31 @@ func initOrb(opts orbOptions) error {
}()

if !gitAction {
_, err = api.CreateOrb(opts.cl, namespace, orbName, false)
if err != nil {
return errors.Wrap(err, "Unable to create orb")
}
err = api.AddOrRemoveOrbCategorization(opts.cl, namespace, orbName, opts.args[1], api.Add)
if err != nil {
return err
}
err = finalizeOrbInit(ownerName, vcsProvider, vcsShort, namespace, orbName, "", &opts)
if err != nil {
return err
}
return nil
}

gitBranch := "main"
bPrompt := &survey.Input{
Message: "Enter your primary git branch.",
Default: gitBranch,
}
err = survey.AskOne(bPrompt, &gitBranch)
if err != nil {
return err
}

gitLocation := ""
iprompt = &survey.Input{
Message: "Enter the remote git repository",
Expand Down Expand Up @@ -1291,7 +1332,7 @@ func initOrb(opts orbOptions) error {
return err
}
err = r.CreateBranch(&config.Branch{
Name: "master",
Name: gitBranch,
Remote: "origin",
})
if err != nil {
Expand Down Expand Up @@ -1332,6 +1373,13 @@ func initOrb(opts orbOptions) error {
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)
if err != nil {
return err
}
}

packedOrb, err := packOrb(filepath.Join(orbPath, "src"))
if err != nil {
return err
Expand All @@ -1354,7 +1402,7 @@ func initOrb(opts orbOptions) error {
return err
}

fmt.Println("An initial commit has been created - please run \033[1;34m'git push origin master'\033[0m to publish your first commit!")
fmt.Printf("An initial commit has been created - please run \033[1;34m'git push origin %v'\033[0m to publish your first commit!\n", gitBranch)
yprompt = &survey.Confirm{
Message: "I have pushed to my git repository using the above command",
}
Expand Down

0 comments on commit 272a716

Please sign in to comment.