You've already forked go-semantic-release
refactor(versioning): clean up version calculation and logs
This commit is contained in:
@@ -13,13 +13,13 @@ type Analyzer struct {
|
||||
|
||||
//Rules for commits
|
||||
type Rules struct {
|
||||
Tag string
|
||||
Release string
|
||||
Enabled bool
|
||||
Tag string
|
||||
Release string
|
||||
Changelog bool
|
||||
}
|
||||
|
||||
type analyzeCommit interface {
|
||||
analyze(commit gitutil.Commit, tag string) (AnalyzedCommit, bool)
|
||||
analyze(commit gitutil.Commit, tag string) (AnalyzedCommit, bool, error)
|
||||
getRules() []Rules
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ type AnalyzedCommit struct {
|
||||
ParsedMessage string
|
||||
Scope string
|
||||
ParsedBreakingChangeMessage string
|
||||
Tag string
|
||||
}
|
||||
|
||||
//New Analyzer struct for given commit format
|
||||
@@ -45,7 +46,7 @@ func (a *Analyzer) Analyze(commits []gitutil.Commit) map[string][]AnalyzedCommit
|
||||
var commitAnalayzer analyzeCommit
|
||||
switch a.CommitFormat {
|
||||
case "angular":
|
||||
log.Infof("analyze angular format")
|
||||
log.Debugf("Commit format set to angular")
|
||||
commitAnalayzer = newAngular()
|
||||
}
|
||||
|
||||
@@ -53,18 +54,24 @@ func (a *Analyzer) Analyze(commits []gitutil.Commit) map[string][]AnalyzedCommit
|
||||
analyzedCommits["major"] = make([]AnalyzedCommit, 0)
|
||||
analyzedCommits["minor"] = make([]AnalyzedCommit, 0)
|
||||
analyzedCommits["patch"] = make([]AnalyzedCommit, 0)
|
||||
analyzedCommits["none"] = make([]AnalyzedCommit, 0)
|
||||
|
||||
for _, commit := range commits {
|
||||
for _, rule := range commitAnalayzer.getRules() {
|
||||
analyzedCommit, hasBreakingChange := commitAnalayzer.analyze(commit, rule.Tag)
|
||||
if hasBreakingChange {
|
||||
analyzedCommits["major"] = append(analyzedCommits["major"], analyzedCommit)
|
||||
} else {
|
||||
analyzedCommits[rule.Release] = append(analyzedCommits[rule.Release], analyzedCommit)
|
||||
analyzedCommit, hasBreakingChange, err := commitAnalayzer.analyze(commit, rule.Tag)
|
||||
if err == nil {
|
||||
if hasBreakingChange {
|
||||
analyzedCommits["major"] = append(analyzedCommits["major"], analyzedCommit)
|
||||
} else {
|
||||
analyzedCommits[rule.Release] = append(analyzedCommits[rule.Release], analyzedCommit)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("Analyzed commits: major=%d minor=%d patch=%d none=%d", len(analyzedCommits["major"]), len(analyzedCommits["minor"]), len(analyzedCommits["patch"]), len(analyzedCommits["none"]))
|
||||
|
||||
return analyzedCommits
|
||||
}
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
package analyzer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
||||
)
|
||||
|
||||
@@ -18,18 +21,43 @@ func newAngular() *angular {
|
||||
regex: `(TAG)(?:\((.*)\))?: (.*)`,
|
||||
rules: []Rules{
|
||||
{
|
||||
Tag: "feat",
|
||||
Release: "minor",
|
||||
Enabled: true,
|
||||
Tag: "feat",
|
||||
Release: "minor",
|
||||
Changelog: true,
|
||||
},
|
||||
{
|
||||
Tag: "fix",
|
||||
Release: "patch",
|
||||
Enabled: true,
|
||||
Tag: "fix",
|
||||
Release: "patch",
|
||||
Changelog: true,
|
||||
}, {
|
||||
Tag: "perf",
|
||||
Release: "patch",
|
||||
Enabled: true,
|
||||
Tag: "perf",
|
||||
Release: "patch",
|
||||
Changelog: true,
|
||||
}, {
|
||||
Tag: "docs",
|
||||
Release: "none",
|
||||
Changelog: false,
|
||||
},
|
||||
{
|
||||
Tag: "style",
|
||||
Release: "none",
|
||||
Changelog: false,
|
||||
}, {
|
||||
Tag: "refactor",
|
||||
Release: "none",
|
||||
Changelog: false,
|
||||
}, {
|
||||
Tag: "test",
|
||||
Release: "none",
|
||||
Changelog: false,
|
||||
}, {
|
||||
Tag: "chore",
|
||||
Release: "none",
|
||||
Changelog: false,
|
||||
}, {
|
||||
Tag: "build",
|
||||
Release: "none",
|
||||
Changelog: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -39,14 +67,15 @@ func (a *angular) getRules() []Rules {
|
||||
return a.rules
|
||||
}
|
||||
|
||||
func (a *angular) analyze(commit gitutil.Commit, tag string) (AnalyzedCommit, bool) {
|
||||
func (a *angular) analyze(commit gitutil.Commit, tag string) (AnalyzedCommit, bool, error) {
|
||||
|
||||
analyzed := AnalyzedCommit{
|
||||
Commit: commit,
|
||||
Tag: tag,
|
||||
}
|
||||
|
||||
re := regexp.MustCompile(strings.Replace(a.regex, "TAG", tag, -1))
|
||||
matches := re.FindAllStringSubmatch(commit.Message+" "+commit.Message, -1)
|
||||
matches := re.FindAllStringSubmatch(commit.Message, -1)
|
||||
if len(matches) >= 1 {
|
||||
if len(matches[0]) >= 3 {
|
||||
analyzed.Scope = matches[0][2]
|
||||
@@ -56,14 +85,17 @@ func (a *angular) analyze(commit gitutil.Commit, tag string) (AnalyzedCommit, bo
|
||||
|
||||
if len(splitted) == 1 {
|
||||
analyzed.ParsedMessage = splitted[0]
|
||||
return analyzed, false
|
||||
log.Tracef("%s: found %s", commit.Message, tag)
|
||||
return analyzed, false, nil
|
||||
}
|
||||
analyzed.ParsedMessage = splitted[0]
|
||||
analyzed.ParsedBreakingChangeMessage = splitted[1]
|
||||
return analyzed, true
|
||||
log.Tracef(" %s, BREAKING CHANGE found", commit.Message)
|
||||
return analyzed, true, nil
|
||||
|
||||
}
|
||||
}
|
||||
return analyzed, false
|
||||
log.Tracef("%s does not match %s, skip", commit.Message, tag)
|
||||
return analyzed, false, fmt.Errorf("Not found")
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user