2026-07-07 00:07:53 +02:00
|
|
|
package version
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"git.k3nny.fr/releaser/internal/commits"
|
|
|
|
|
)
|
|
|
|
|
|
2026-07-11 16:59:28 +02:00
|
|
|
// BumpLevel controls which version component is incremented.
|
|
|
|
|
type BumpLevel int
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
BumpPatch BumpLevel = iota
|
|
|
|
|
BumpMinor
|
|
|
|
|
)
|
|
|
|
|
|
2026-07-07 00:07:53 +02:00
|
|
|
// Next computes the next version string (without tag prefix, e.g. "1.2.4").
|
|
|
|
|
// currentPatch is -1 when no tag exists yet (first release will be X.Y.0).
|
2026-07-11 00:15:09 +02:00
|
|
|
// releasable is the set of commit types that trigger a bump; nil defaults to all three.
|
2026-07-11 16:59:28 +02:00
|
|
|
// bumpRules maps each type to its bump level; nil defaults to BumpPatch for all.
|
2026-07-07 00:07:53 +02:00
|
|
|
// Returns ("", false) when there are no releasable commits.
|
2026-07-11 16:59:28 +02:00
|
|
|
func Next(major, minor, currentPatch int, types []commits.Type, releasable map[commits.Type]bool, bumpRules map[commits.Type]BumpLevel) (string, bool) {
|
2026-07-11 00:15:09 +02:00
|
|
|
if releasable == nil {
|
|
|
|
|
releasable = commits.ReleasableSet(nil)
|
|
|
|
|
}
|
2026-07-11 16:59:28 +02:00
|
|
|
found := false
|
|
|
|
|
useMinor := false
|
2026-07-07 00:07:53 +02:00
|
|
|
for _, t := range types {
|
2026-07-11 00:15:09 +02:00
|
|
|
if releasable[t] {
|
2026-07-11 16:59:28 +02:00
|
|
|
found = true
|
|
|
|
|
if bumpRules[t] == BumpMinor {
|
|
|
|
|
useMinor = true
|
|
|
|
|
}
|
2026-07-07 00:07:53 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-07-11 16:59:28 +02:00
|
|
|
if !found {
|
|
|
|
|
return "", false
|
|
|
|
|
}
|
|
|
|
|
if useMinor {
|
|
|
|
|
return fmt.Sprintf("%d.%d.0", major, minor+1), true
|
|
|
|
|
}
|
|
|
|
|
return fmt.Sprintf("%d.%d.%d", major, minor, currentPatch+1), true
|
2026-07-07 00:07:53 +02:00
|
|
|
}
|