You've already forked go-semantic-release
ref(analyzer): simplified analyze method for angular and conventional
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
package analyzer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
@@ -36,12 +35,14 @@ func newAngular() *angular {
|
||||
TagString: "Bug fixes",
|
||||
Release: "patch",
|
||||
Changelog: true,
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Tag: "perf",
|
||||
TagString: "Performance improvments",
|
||||
TagString: "Performance improvements",
|
||||
Release: "patch",
|
||||
Changelog: true,
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Tag: "docs",
|
||||
TagString: "Documentation changes",
|
||||
Release: "none",
|
||||
@@ -52,22 +53,26 @@ func newAngular() *angular {
|
||||
TagString: "Style",
|
||||
Release: "none",
|
||||
Changelog: false,
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Tag: "refactor",
|
||||
TagString: "Code refactor",
|
||||
Release: "none",
|
||||
Changelog: false,
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Tag: "test",
|
||||
TagString: "Testing",
|
||||
Release: "none",
|
||||
Changelog: false,
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Tag: "chore",
|
||||
TagString: "Changes to the build process or auxiliary tools and libraries such as documentation generation",
|
||||
Release: "none",
|
||||
Changelog: false,
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Tag: "build",
|
||||
TagString: "Changes to CI/CD",
|
||||
Release: "none",
|
||||
@@ -81,38 +86,37 @@ func (a *angular) getRules() []Rule {
|
||||
return a.rules
|
||||
}
|
||||
|
||||
func (a *angular) analyze(commit shared.Commit, rule Rule) (shared.AnalyzedCommit, bool, error) {
|
||||
func (a *angular) analyze(commit shared.Commit, rule Rule) (*shared.AnalyzedCommit, bool) {
|
||||
re := regexp.MustCompile(strings.Replace(a.regex, "TAG", rule.Tag, -1))
|
||||
matches := re.FindStringSubmatch(commit.Message)
|
||||
if matches == nil {
|
||||
a.log.Tracef("%s does not match %s, skip", commit.Message, rule.Tag)
|
||||
return nil, false
|
||||
}
|
||||
|
||||
analyzed := shared.AnalyzedCommit{
|
||||
analyzed := &shared.AnalyzedCommit{
|
||||
Commit: commit,
|
||||
Tag: rule.Tag,
|
||||
TagString: rule.TagString,
|
||||
Scope: shared.Scope(matches[2]),
|
||||
}
|
||||
|
||||
re := regexp.MustCompile(strings.Replace(a.regex, "TAG", rule.Tag, -1))
|
||||
matches := re.FindAllStringSubmatch(commit.Message, -1)
|
||||
if len(matches) >= 1 {
|
||||
if len(matches[0]) >= 3 {
|
||||
|
||||
analyzed.Scope = shared.Scope(matches[0][2])
|
||||
|
||||
message := strings.Join(matches[0][3:], "")
|
||||
if !strings.Contains(message, "BREAKING CHANGE:") {
|
||||
analyzed.ParsedMessage = strings.Trim(message, " ")
|
||||
|
||||
a.log.Tracef("%s: found %s", commit.Message, rule.Tag)
|
||||
return analyzed, false, nil
|
||||
}
|
||||
breakingChange := strings.SplitN(message, "BREAKING CHANGE:", 2)
|
||||
|
||||
analyzed.ParsedMessage = strings.TrimSpace(breakingChange[0])
|
||||
analyzed.ParsedBreakingChangeMessage = strings.TrimSpace(breakingChange[1])
|
||||
|
||||
a.log.Tracef(" %s, BREAKING CHANGE found", commit.Message)
|
||||
return analyzed, true, nil
|
||||
}
|
||||
message := strings.Join(matches[3:], "")
|
||||
if !strings.Contains(message, "BREAKING CHANGE:") {
|
||||
analyzed.ParsedMessage = strings.Trim(message, " ")
|
||||
a.log.Tracef("%s: found %s", commit.Message, rule.Tag)
|
||||
return analyzed, false
|
||||
}
|
||||
a.log.Tracef("%s does not match %s, skip", commit.Message, rule.Tag)
|
||||
return analyzed, false, fmt.Errorf("not found")
|
||||
|
||||
a.log.Tracef(" %s, BREAKING CHANGE found", commit.Message)
|
||||
breakingChange := strings.SplitN(message, "BREAKING CHANGE:", 2)
|
||||
|
||||
if len(breakingChange) > 1 {
|
||||
analyzed.ParsedMessage = strings.TrimSpace(breakingChange[0])
|
||||
analyzed.ParsedBreakingChangeMessage = strings.TrimSpace(breakingChange[1])
|
||||
return analyzed, true
|
||||
}
|
||||
|
||||
analyzed.ParsedBreakingChangeMessage = breakingChange[0]
|
||||
return analyzed, true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user