You've already forked go-semantic-release
feat(analyzer): add 'DRAFT' as messeage identifier
This commit is contained in:
@@ -24,7 +24,7 @@ type Rule struct {
|
||||
}
|
||||
|
||||
type analyzeCommit interface {
|
||||
analyze(commit gitutil.Commit, tag Rule) (AnalyzedCommit, bool, error)
|
||||
analyze(commit gitutil.Commit, tag Rule) (AnalyzedCommit, bool, bool, error)
|
||||
getRules() []Rule
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ type AnalyzedCommit struct {
|
||||
ParsedMessage string
|
||||
Scope string
|
||||
ParsedBreakingChangeMessage string
|
||||
ParsedDraftMessage string
|
||||
Tag string
|
||||
TagString string
|
||||
Print bool
|
||||
@@ -68,11 +69,12 @@ 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["draft"] = make([]AnalyzedCommit, 0)
|
||||
analyzedCommits["none"] = make([]AnalyzedCommit, 0)
|
||||
|
||||
for _, commit := range commits {
|
||||
for _, rule := range a.analyzeCommit.getRules() {
|
||||
analyzedCommit, hasBreakingChange, err := a.analyzeCommit.analyze(commit, rule)
|
||||
analyzedCommit, hasBreakingChange, isDraft, err := a.analyzeCommit.analyze(commit, rule)
|
||||
if err == nil {
|
||||
if a.Config.PrintAll {
|
||||
analyzedCommit.Print = true
|
||||
@@ -81,6 +83,8 @@ func (a *Analyzer) Analyze(commits []gitutil.Commit) map[string][]AnalyzedCommit
|
||||
}
|
||||
if hasBreakingChange {
|
||||
analyzedCommits["major"] = append(analyzedCommits["major"], analyzedCommit)
|
||||
} else if isDraft {
|
||||
analyzedCommits["draft"] = append(analyzedCommits["draft"], analyzedCommit)
|
||||
} else {
|
||||
analyzedCommits[rule.Release] = append(analyzedCommits[rule.Release], analyzedCommit)
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ func (a *angular) getRules() []Rule {
|
||||
return a.rules
|
||||
}
|
||||
|
||||
func (a *angular) analyze(commit gitutil.Commit, rule Rule) (AnalyzedCommit, bool, error) {
|
||||
func (a *angular) analyze(commit gitutil.Commit, rule Rule) (AnalyzedCommit, bool, bool, error) {
|
||||
|
||||
analyzed := AnalyzedCommit{
|
||||
Commit: commit,
|
||||
@@ -92,21 +92,35 @@ func (a *angular) analyze(commit gitutil.Commit, rule Rule) (AnalyzedCommit, boo
|
||||
analyzed.Scope = matches[0][2]
|
||||
|
||||
message := strings.Join(matches[0][3:], "")
|
||||
splitted := strings.SplitN(message, "BREAKING CHANGE:", 1)
|
||||
breakingChange := strings.SplitN(message, "BREAKING CHANGE:", 1)
|
||||
draft := strings.SplitN(message, "DRAFT:", 1)
|
||||
|
||||
if len(splitted) == 1 {
|
||||
analyzed.ParsedMessage = splitted[0]
|
||||
if len(breakingChange) == 1 && len(draft) == 1 {
|
||||
analyzed.ParsedMessage = breakingChange[0]
|
||||
log.Tracef("%s: found %s", commit.Message, rule.Tag)
|
||||
return analyzed, false, nil
|
||||
return analyzed, false, false, nil
|
||||
|
||||
}
|
||||
|
||||
if len(breakingChange) > 1 {
|
||||
|
||||
analyzed.ParsedMessage = breakingChange[0]
|
||||
analyzed.ParsedBreakingChangeMessage = breakingChange[1]
|
||||
|
||||
log.Tracef(" %s, BREAKING CHANGE found", commit.Message)
|
||||
|
||||
return analyzed, true, false, nil
|
||||
|
||||
} else if len(draft) > 1 {
|
||||
analyzed.ParsedMessage = draft[0]
|
||||
analyzed.ParsedDraftMessage = draft[1]
|
||||
log.Tracef(" %s, DRAFT found", commit.Message)
|
||||
|
||||
}
|
||||
analyzed.ParsedMessage = splitted[0]
|
||||
analyzed.ParsedBreakingChangeMessage = splitted[1]
|
||||
log.Tracef(" %s, BREAKING CHANGE found", commit.Message)
|
||||
return analyzed, true, nil
|
||||
|
||||
}
|
||||
}
|
||||
log.Tracef("%s does not match %s, skip", commit.Message, rule.Tag)
|
||||
return analyzed, false, fmt.Errorf("not found")
|
||||
return analyzed, false, false, fmt.Errorf("not found")
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user