mirror of
https://github.com/Luzifer/git-changerelease.git
synced 2024-12-20 11:01:16 +00:00
fix wrong bump when patch and minor are included
In previous versions the bump type was not calculated correctly when a minor commit and a patch type commit were included in a release. Instead of using the minor-bump it used the patch-bump because minor was the default and patch overruled minor.
This commit is contained in:
parent
bb7a2bedfe
commit
fa7cfd9e9e
3 changed files with 45 additions and 25 deletions
18
git.go
18
git.go
|
@ -27,6 +27,7 @@ type commit struct {
|
|||
Subject string
|
||||
AuthorName string
|
||||
AuthorEmail string
|
||||
BumpType semVerBump
|
||||
}
|
||||
|
||||
func parseCommit(line string) (*commit, error) {
|
||||
|
@ -34,12 +35,25 @@ func parseCommit(line string) (*commit, error) {
|
|||
if len(t) != 4 {
|
||||
return nil, errors.New("Unexpected line format")
|
||||
}
|
||||
return &commit{
|
||||
|
||||
c := &commit{
|
||||
ShortHash: t[0],
|
||||
Subject: t[1],
|
||||
AuthorName: t[2],
|
||||
AuthorEmail: t[3],
|
||||
}, nil
|
||||
}
|
||||
|
||||
for rex, bt := range matchers {
|
||||
if rex.MatchString(c.Subject) && bt > c.BumpType {
|
||||
c.BumpType = bt
|
||||
}
|
||||
}
|
||||
|
||||
if c.BumpType == semVerBumpUndecided {
|
||||
c.BumpType = semVerBumpMinor
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func git(stderrEnabled bool, args ...string) (string, error) {
|
||||
|
|
19
main.go
19
main.go
|
@ -11,6 +11,7 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -41,6 +42,8 @@ var (
|
|||
|
||||
config configFile
|
||||
version = "dev"
|
||||
|
||||
matchers = make(map[*regexp.Regexp]semVerBump)
|
||||
)
|
||||
|
||||
func prepareRun() {
|
||||
|
@ -73,6 +76,22 @@ func prepareRun() {
|
|||
if err := loadConfig(); err != nil {
|
||||
log.Fatalf("Unable to load config file: %s", err)
|
||||
}
|
||||
|
||||
// Collect matchers
|
||||
for _, m := range config.MatchPatch {
|
||||
r, err := regexp.Compile(m)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to parse regex '%s': %s", m, err)
|
||||
}
|
||||
matchers[r] = semVerBumpPatch
|
||||
}
|
||||
for _, m := range config.MatchMajor {
|
||||
r, err := regexp.Compile(m)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to parse regex '%s': %s", m, err)
|
||||
}
|
||||
matchers[r] = semVerBumpMajor
|
||||
}
|
||||
}
|
||||
|
||||
func loadConfig() error {
|
||||
|
|
33
semver.go
33
semver.go
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
@ -10,8 +9,9 @@ import (
|
|||
type semVerBump uint
|
||||
|
||||
const (
|
||||
semVerBumpMinor semVerBump = iota
|
||||
semVerBumpUndecided semVerBump = iota
|
||||
semVerBumpPatch
|
||||
semVerBumpMinor
|
||||
semVerBumpMajor
|
||||
)
|
||||
|
||||
|
@ -91,31 +91,18 @@ func (s *semVer) Bump(bumpType semVerBump) {
|
|||
}
|
||||
|
||||
func selectBumpType(logs []commit) (semVerBump, error) {
|
||||
bump := semVerBumpMinor
|
||||
|
||||
matchers := map[*regexp.Regexp]semVerBump{}
|
||||
for _, m := range config.MatchPatch {
|
||||
r, err := regexp.Compile(m)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
matchers[r] = semVerBumpPatch
|
||||
}
|
||||
for _, m := range config.MatchMajor {
|
||||
r, err := regexp.Compile(m)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
matchers[r] = semVerBumpMajor
|
||||
}
|
||||
bump := semVerBumpUndecided
|
||||
|
||||
for _, l := range logs {
|
||||
for m, t := range matchers {
|
||||
if m.MatchString(l.Subject) && t > bump {
|
||||
bump = t
|
||||
}
|
||||
if l.BumpType > bump {
|
||||
bump = l.BumpType
|
||||
}
|
||||
}
|
||||
|
||||
if bump == semVerBumpUndecided {
|
||||
// Impossible to reach
|
||||
return semVerBumpUndecided, errors.New("Could not decide for any bump type!")
|
||||
}
|
||||
|
||||
return bump, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue