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"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NextVersionHandler(g app.GitSV) 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)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2023-10-15 19:29:29 +00:00
|
|
|
|
|
|
|
fmt.Printf("%d.%d.%d\n", nextVer.Major(), nextVer.Minor(), nextVer.Patch())
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|