You've already forked go-semantic-release
ref(analyzer): simplified analyze method for angular and conventional
This commit is contained in:
@@ -9,13 +9,13 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
//Analyzer struct
|
||||
// Analyzer struct
|
||||
type Analyzer struct {
|
||||
analyzeCommits analyzeCommits
|
||||
Config config.ChangelogConfig
|
||||
}
|
||||
|
||||
//Rule for commits
|
||||
// Rule for commits
|
||||
type Rule struct {
|
||||
Tag string
|
||||
TagString string
|
||||
@@ -24,11 +24,11 @@ type Rule struct {
|
||||
}
|
||||
|
||||
type analyzeCommits interface {
|
||||
analyze(commit shared.Commit, tag Rule) (shared.AnalyzedCommit, bool, error)
|
||||
analyze(commit shared.Commit, tag Rule) (*shared.AnalyzedCommit, bool)
|
||||
getRules() []Rule
|
||||
}
|
||||
|
||||
//New Analyzer struct for given commit format
|
||||
// New Analyzer struct for given commit format
|
||||
func New(format string, config config.ChangelogConfig) (*Analyzer, error) {
|
||||
analyzer := &Analyzer{
|
||||
Config: config,
|
||||
@@ -45,7 +45,6 @@ func New(format string, config config.ChangelogConfig) (*Analyzer, error) {
|
||||
return nil, fmt.Errorf("invalid commit format: %s", format)
|
||||
}
|
||||
return analyzer, nil
|
||||
|
||||
}
|
||||
|
||||
// GetRules from current mode
|
||||
@@ -53,9 +52,8 @@ func (a *Analyzer) GetRules() []Rule {
|
||||
return a.analyzeCommits.getRules()
|
||||
}
|
||||
|
||||
// Analyze commits and return commits splitted by major,minor,patch
|
||||
// Analyze commits and return commits split by major,minor,patch
|
||||
func (a *Analyzer) Analyze(commits []shared.Commit) map[shared.Release][]shared.AnalyzedCommit {
|
||||
|
||||
analyzedCommits := make(map[shared.Release][]shared.AnalyzedCommit)
|
||||
analyzedCommits["major"] = make([]shared.AnalyzedCommit, 0)
|
||||
analyzedCommits["minor"] = make([]shared.AnalyzedCommit, 0)
|
||||
@@ -64,25 +62,21 @@ func (a *Analyzer) Analyze(commits []shared.Commit) map[shared.Release][]shared.
|
||||
|
||||
for _, commit := range commits {
|
||||
for _, rule := range a.analyzeCommits.getRules() {
|
||||
analyzedCommit, hasBreakingChange, err := a.analyzeCommits.analyze(commit, rule)
|
||||
if err == nil {
|
||||
if a.Config.PrintAll {
|
||||
analyzedCommit.Print = true
|
||||
} else {
|
||||
analyzedCommit.Print = rule.Changelog
|
||||
}
|
||||
if hasBreakingChange {
|
||||
analyzedCommits["major"] = append(analyzedCommits["major"], analyzedCommit)
|
||||
} else {
|
||||
analyzedCommits[rule.Release] = append(analyzedCommits[rule.Release], analyzedCommit)
|
||||
}
|
||||
analyzedCommit, hasBreakingChange := a.analyzeCommits.analyze(commit, rule)
|
||||
if analyzedCommit == nil {
|
||||
continue
|
||||
}
|
||||
if a.Config.PrintAll || rule.Changelog {
|
||||
analyzedCommit.Print = true
|
||||
}
|
||||
if hasBreakingChange {
|
||||
analyzedCommits["major"] = append(analyzedCommits["major"], *analyzedCommit)
|
||||
break
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user