github.com/azunymous/cdx@v0.0.0-20201122180449-fbb46cc4d252/commands/promote.go (about)

     1  package commands
     2  
     3  import (
     4  	"github.com/azunymous/cdx/commands/options"
     5  	"github.com/azunymous/cdx/vcs"
     6  	"github.com/azunymous/cdx/vcs/gogit"
     7  	"github.com/sirupsen/logrus"
     8  	"github.com/spf13/cobra"
     9  )
    10  
    11  // addRelease adds the increment command to a top level command.
    12  func addPromote(topLevel *cobra.Command, app *options.App) {
    13  	gitOpts := &options.Git{}
    14  	releaseCmd := &cobra.Command{
    15  		Use:   "promote <stage>",
    16  		Short: "Promote this commit",
    17  		Long: `The promote command promotes the current commit via a git tag
    18  `,
    19  		Run: func(cmd *cobra.Command, args []string) {
    20  			err := promote(app, gitOpts, args[0])
    21  			if err != nil {
    22  				logrus.Fatal(err)
    23  			}
    24  		},
    25  		Args: cobra.ExactArgs(1),
    26  	}
    27  	options.AddPushArg(releaseCmd, gitOpts)
    28  	topLevel.AddCommand(releaseCmd)
    29  }
    30  
    31  func promote(app *options.App, gitOpts *options.Git, stage string) error {
    32  	logrus.Printf("Promoting %s to %s", app.Name, stage)
    33  	v, err := vcs.NewGit(app.Name, -1, gitOpts.Push, func() (vcs.Repository, error) { return gogit.NewRepo() })
    34  	if err != nil {
    35  		return err
    36  	}
    37  	err = v.Promote(stage)
    38  	if err != nil {
    39  		return err
    40  	}
    41  	return v.Distribute()
    42  }