feat: teach catalogue generate to use git

This commit is contained in:
2021-11-07 00:03:01 +01:00
parent 2b9395be1a
commit 1467ae5007
3 changed files with 152 additions and 70 deletions

View File

@ -20,40 +20,6 @@ import (
"github.com/urfave/cli/v2"
)
var Push bool
var PushFlag = &cli.BoolFlag{
Name: "push",
Usage: "Git push changes",
Value: false,
Aliases: []string{"P"},
Destination: &Push,
}
var CommitMessage string
var CommitMessageFlag = &cli.StringFlag{
Name: "commit-message",
Usage: "Commit message (implies --commit)",
Aliases: []string{"cm"},
Destination: &CommitMessage,
}
var Commit bool
var CommitFlag = &cli.BoolFlag{
Name: "commit",
Usage: "Commits compose.**yml file changes to recipe repository",
Value: false,
Aliases: []string{"c"},
Destination: &Commit,
}
var TagMessage string
var TagMessageFlag = &cli.StringFlag{
Name: "tag-comment",
Usage: "Description for release tag",
Aliases: []string{"t", "tm"},
Destination: &TagMessage,
}
var recipeReleaseCommand = &cli.Command{
Name: "release",
Usage: "Release a new recipe version",
@ -90,10 +56,10 @@ You may invoke this command in "wizard" mode and be prompted for input:
internal.MajorFlag,
internal.MinorFlag,
internal.PatchFlag,
PushFlag,
CommitFlag,
CommitMessageFlag,
TagMessageFlag,
internal.PushFlag,
internal.CommitFlag,
internal.CommitMessageFlag,
internal.TagMessageFlag,
},
Action: func(c *cli.Context) error {
recipe := internal.ValidateRecipeWithPrompt(c)
@ -142,38 +108,38 @@ You may invoke this command in "wizard" mode and be prompted for input:
logrus.Fatal(err)
}
if TagMessage == "" {
if internal.TagMessage == "" {
prompt := &survey.Input{
Message: "tag message",
Default: fmt.Sprintf("chore: publish new %s version", internal.GetBumpType()),
}
if err := survey.AskOne(prompt, &TagMessage); err != nil {
if err := survey.AskOne(prompt, &internal.TagMessage); err != nil {
logrus.Fatal(err)
}
}
var createTagOptions git.CreateTagOptions
createTagOptions.Message = TagMessage
createTagOptions.Message = internal.TagMessage
if !Commit {
if !internal.Commit {
prompt := &survey.Confirm{
Message: "git commit changes also?",
}
if err := survey.AskOne(prompt, &Commit); err != nil {
if err := survey.AskOne(prompt, &internal.Commit); err != nil {
return err
}
}
if !Push {
if !internal.Push {
prompt := &survey.Confirm{
Message: "git push changes also?",
}
if err := survey.AskOne(prompt, &Push); err != nil {
if err := survey.AskOne(prompt, &internal.Push); err != nil {
return err
}
}
if Commit || CommitMessage != "" {
if internal.Commit || internal.CommitMessage != "" {
commitRepo, err := git.PlainOpen(directory)
if err != nil {
logrus.Fatal(err)
@ -183,12 +149,12 @@ You may invoke this command in "wizard" mode and be prompted for input:
logrus.Fatal(err)
}
if CommitMessage == "" {
if internal.CommitMessage == "" {
prompt := &survey.Input{
Message: "commit message",
Default: fmt.Sprintf("chore: publish new %s version", internal.GetBumpType()),
}
if err := survey.AskOne(prompt, &CommitMessage); err != nil {
if err := survey.AskOne(prompt, &internal.CommitMessage); err != nil {
logrus.Fatal(err)
}
}
@ -200,7 +166,7 @@ You may invoke this command in "wizard" mode and be prompted for input:
logrus.Debug("staged compose.**yml for commit")
if !internal.Dry {
_, err = commitWorktree.Commit(CommitMessage, &git.CommitOptions{})
_, err = commitWorktree.Commit(internal.CommitMessage, &git.CommitOptions{})
if err != nil {
logrus.Fatal(err)
}
@ -242,7 +208,7 @@ You may invoke this command in "wizard" mode and be prompted for input:
repo.CreateTag(tagString, head.Hash(), &createTagOptions)
hash := abraFormatter.SmallSHA(head.Hash().String())
logrus.Info(fmt.Sprintf("created tag %s at %s", tagString, hash))
if Push && !internal.Dry {
if internal.Push && !internal.Dry {
if err := repo.Push(&git.PushOptions{}); err != nil {
logrus.Fatal(err)
}
@ -317,7 +283,7 @@ You may invoke this command in "wizard" mode and be prompted for input:
repo.CreateTag(newtagString, head.Hash(), &createTagOptions)
hash := abraFormatter.SmallSHA(head.Hash().String())
logrus.Info(fmt.Sprintf("created tag %s at %s", newtagString, hash))
if Push && !internal.Dry {
if internal.Push && !internal.Dry {
if err := repo.Push(&git.PushOptions{}); err != nil {
logrus.Fatal(err)
}