2023-10-15 19:29:29 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2023-10-17 13:23:00 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
2023-10-16 19:41:33 +00:00
|
|
|
"github.com/thegeeklab/git-sv/app"
|
|
|
|
"github.com/thegeeklab/git-sv/sv"
|
2023-10-15 19:29:29 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
2023-10-18 13:51:05 +00:00
|
|
|
func TagFlags(settings *app.TagSettings) []cli.Flag {
|
|
|
|
return []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "annotate",
|
|
|
|
Aliases: []string{"a"},
|
2023-10-18 14:09:13 +00:00
|
|
|
Usage: "make an annotated tag object",
|
2023-10-18 13:51:05 +00:00
|
|
|
Destination: &settings.Annotate,
|
|
|
|
},
|
2023-10-18 14:09:13 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "local",
|
|
|
|
Usage: "create local tag only",
|
|
|
|
Destination: &settings.Local,
|
|
|
|
},
|
2023-10-18 13:51:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TagHandler(g app.GitSV, settings *app.TagSettings) cli.ActionFunc {
|
2024-02-12 08:09:42 +00:00
|
|
|
return func(_ *cli.Context) error {
|
2023-10-15 19:29:29 +00:00
|
|
|
lastTag := g.LastTag()
|
|
|
|
|
|
|
|
currentVer, err := sv.ToVersion(lastTag)
|
|
|
|
if err != nil {
|
2023-10-15 22:29:02 +00:00
|
|
|
return fmt.Errorf("error parsing version: %s from git tag: %w", lastTag, err)
|
2023-10-15 19:29:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
commits, err := g.Log(app.NewLogRange(app.TagRange, lastTag, ""))
|
|
|
|
if err != nil {
|
2023-10-15 22:29:02 +00:00
|
|
|
return fmt.Errorf("error getting git log: %w", err)
|
2023-10-15 19:29:29 +00:00
|
|
|
}
|
|
|
|
|
2023-10-17 13:23:00 +00:00
|
|
|
nextVer, updated := g.CommitProcessor.NextVersion(currentVer, commits)
|
|
|
|
if !updated {
|
|
|
|
log.Info().Msgf("nothing to do: current version %s unchanged", currentVer)
|
2023-10-15 19:29:29 +00:00
|
|
|
|
2023-10-17 13:23:00 +00:00
|
|
|
return nil
|
|
|
|
}
|
2023-10-15 19:29:29 +00:00
|
|
|
|
2023-10-18 14:09:13 +00:00
|
|
|
tagname, err := g.Tag(*nextVer, settings.Annotate, settings.Local)
|
2023-10-15 19:29:29 +00:00
|
|
|
if err != nil {
|
2023-10-15 22:29:02 +00:00
|
|
|
return fmt.Errorf("error generating tag version: %s: %w", nextVer.String(), err)
|
2023-10-15 19:29:29 +00:00
|
|
|
}
|
|
|
|
|
2023-10-17 13:23:00 +00:00
|
|
|
fmt.Println(tagname)
|
|
|
|
|
2023-10-15 19:29:29 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|