2019-05-14 20:19:36 +02:00
|
|
|
// Package analyzer provides different commit analyzer
|
2019-05-13 22:36:24 +02:00
|
|
|
package analyzer
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"regexp"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
|
|
|
|
)
|
|
|
|
|
|
2019-05-14 20:19:36 +02:00
|
|
|
type angular struct {
|
2019-05-13 22:36:24 +02:00
|
|
|
rules []Rules
|
|
|
|
|
regex string
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-14 20:19:36 +02:00
|
|
|
func newAngular() *angular {
|
|
|
|
|
return &angular{
|
2019-05-13 22:36:24 +02:00
|
|
|
regex: `(TAG)(?:\((.*)\))?: (.*)`,
|
|
|
|
|
rules: []Rules{
|
|
|
|
|
{
|
|
|
|
|
Tag: "feat",
|
|
|
|
|
Release: "minor",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Tag: "fix",
|
|
|
|
|
Release: "patch",
|
|
|
|
|
}, {
|
|
|
|
|
Tag: "perf",
|
|
|
|
|
Release: "patch",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-14 20:19:36 +02:00
|
|
|
func (a *angular) getRules() []Rules {
|
2019-05-13 22:36:24 +02:00
|
|
|
return a.rules
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-14 20:19:36 +02:00
|
|
|
func (a *angular) analyze(commit gitutil.Commit, tag string) (AnalyzedCommit, bool) {
|
2019-05-13 22:36:24 +02:00
|
|
|
|
|
|
|
|
analyzed := AnalyzedCommit{
|
|
|
|
|
Commit: commit,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
re := regexp.MustCompile(strings.Replace(a.regex, "TAG", tag, -1))
|
|
|
|
|
matches := re.FindAllStringSubmatch(commit.Message+" "+commit.Message, -1)
|
|
|
|
|
if len(matches) >= 1 {
|
|
|
|
|
if len(matches[0]) >= 3 {
|
|
|
|
|
analyzed.Scope = matches[0][2]
|
|
|
|
|
|
|
|
|
|
message := strings.Join(matches[0][3:], "")
|
|
|
|
|
splitted := strings.SplitN(message, "BREAKING CHANGE:", 1)
|
|
|
|
|
|
|
|
|
|
if len(splitted) == 1 {
|
|
|
|
|
analyzed.ParsedMessage = splitted[0]
|
|
|
|
|
return analyzed, false
|
|
|
|
|
}
|
|
|
|
|
analyzed.ParsedMessage = splitted[0]
|
|
|
|
|
analyzed.ParsedBreakingChangeMessage = splitted[1]
|
|
|
|
|
return analyzed, true
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return analyzed, false
|
|
|
|
|
|
|
|
|
|
}
|