mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-27 00:10:34 +00:00
2d2de1a5e0
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Robert Kaussow <mail@thegeeklab.de>
38 lines
860 B
Go
38 lines
860 B
Go
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
"github.com/thegeeklab/git-sv/app"
|
|
"github.com/thegeeklab/git-sv/sv"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
func NextVersionHandler(g app.GitSV) cli.ActionFunc {
|
|
return func(_ *cli.Context) error {
|
|
lastTag := g.LastTag()
|
|
|
|
currentVer, err := sv.ToVersion(lastTag)
|
|
if err != nil {
|
|
return fmt.Errorf("error parsing version: %s from git tag: %w", lastTag, err)
|
|
}
|
|
|
|
commits, err := g.Log(app.NewLogRange(app.TagRange, lastTag, ""))
|
|
if err != nil {
|
|
return fmt.Errorf("error getting git log: %w", err)
|
|
}
|
|
|
|
nextVer, updated := g.CommitProcessor.NextVersion(currentVer, commits)
|
|
if !updated {
|
|
log.Info().Msgf("nothing to do: current version %s unchanged", currentVer)
|
|
|
|
return nil
|
|
}
|
|
|
|
fmt.Printf("%d.%d.%d\n", nextVer.Major(), nextVer.Minor(), nextVer.Patch())
|
|
|
|
return nil
|
|
}
|
|
}
|