You've already forked go-semantic-release
fix(cache): save commits to cache to avoid empty changelog
This commit is contained in:
@@ -4,47 +4,30 @@ package analyzer
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
||||
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
//Analyzer struct
|
||||
type Analyzer struct {
|
||||
analyzeCommit analyzeCommit
|
||||
Config config.ChangelogConfig
|
||||
analyzeCommits analyzeCommits
|
||||
Config config.ChangelogConfig
|
||||
}
|
||||
|
||||
//Release types, like major
|
||||
type Release string
|
||||
|
||||
//Scope of the commit, like feat, fix,..
|
||||
type Scope string
|
||||
|
||||
//Rule for commits
|
||||
type Rule struct {
|
||||
Tag string
|
||||
TagString string
|
||||
Release Release
|
||||
Release shared.Release
|
||||
Changelog bool
|
||||
}
|
||||
|
||||
type analyzeCommit interface {
|
||||
analyze(commit gitutil.Commit, tag Rule) (AnalyzedCommit, bool, error)
|
||||
type analyzeCommits interface {
|
||||
analyze(commit shared.Commit, tag Rule) (shared.AnalyzedCommit, bool, error)
|
||||
getRules() []Rule
|
||||
}
|
||||
|
||||
//AnalyzedCommit struct
|
||||
type AnalyzedCommit struct {
|
||||
Commit gitutil.Commit
|
||||
ParsedMessage string
|
||||
Scope Scope
|
||||
ParsedBreakingChangeMessage string
|
||||
Tag string
|
||||
TagString string
|
||||
Print bool
|
||||
}
|
||||
|
||||
//New Analyzer struct for given commit format
|
||||
func New(format string, config config.ChangelogConfig) (*Analyzer, error) {
|
||||
analyzer := &Analyzer{
|
||||
@@ -52,9 +35,9 @@ func New(format string, config config.ChangelogConfig) (*Analyzer, error) {
|
||||
}
|
||||
|
||||
switch format {
|
||||
case "angular":
|
||||
log.Debugf("Commit format set to angular")
|
||||
analyzer.analyzeCommit = newAngular()
|
||||
case ANGULAR:
|
||||
analyzer.analyzeCommits = newAngular()
|
||||
log.Debugf("Commit format set to %s", ANGULAR)
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid commit format: %s", format)
|
||||
}
|
||||
@@ -64,21 +47,21 @@ func New(format string, config config.ChangelogConfig) (*Analyzer, error) {
|
||||
|
||||
// GetRules from current mode
|
||||
func (a *Analyzer) GetRules() []Rule {
|
||||
return a.analyzeCommit.getRules()
|
||||
return a.analyzeCommits.getRules()
|
||||
}
|
||||
|
||||
// Analyze commits and return commits splitted by major,minor,patch
|
||||
func (a *Analyzer) Analyze(commits []gitutil.Commit) map[Release][]AnalyzedCommit {
|
||||
func (a *Analyzer) Analyze(commits []shared.Commit) map[shared.Release][]shared.AnalyzedCommit {
|
||||
|
||||
analyzedCommits := make(map[Release][]AnalyzedCommit)
|
||||
analyzedCommits["major"] = make([]AnalyzedCommit, 0)
|
||||
analyzedCommits["minor"] = make([]AnalyzedCommit, 0)
|
||||
analyzedCommits["patch"] = make([]AnalyzedCommit, 0)
|
||||
analyzedCommits["none"] = make([]AnalyzedCommit, 0)
|
||||
analyzedCommits := make(map[shared.Release][]shared.AnalyzedCommit)
|
||||
analyzedCommits["major"] = make([]shared.AnalyzedCommit, 0)
|
||||
analyzedCommits["minor"] = make([]shared.AnalyzedCommit, 0)
|
||||
analyzedCommits["patch"] = make([]shared.AnalyzedCommit, 0)
|
||||
analyzedCommits["none"] = make([]shared.AnalyzedCommit, 0)
|
||||
|
||||
for _, commit := range commits {
|
||||
for _, rule := range a.analyzeCommit.getRules() {
|
||||
analyzedCommit, hasBreakingChange, err := a.analyzeCommit.analyze(commit, rule)
|
||||
for _, rule := range a.analyzeCommits.getRules() {
|
||||
analyzedCommit, hasBreakingChange, err := a.analyzeCommits.analyze(commit, rule)
|
||||
if err == nil {
|
||||
if a.Config.PrintAll {
|
||||
analyzedCommit.Print = true
|
||||
|
||||
@@ -8,17 +8,22 @@ import (
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
||||
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||
)
|
||||
|
||||
type angular struct {
|
||||
rules []Rule
|
||||
regex string
|
||||
log *log.Entry
|
||||
}
|
||||
|
||||
// ANGULAR identifer
|
||||
const ANGULAR = "angular"
|
||||
|
||||
func newAngular() *angular {
|
||||
return &angular{
|
||||
regex: `(TAG)(?:\((.*)\))?: (.*)`,
|
||||
log: log.WithField("analyzer", ANGULAR),
|
||||
rules: []Rule{
|
||||
{
|
||||
Tag: "feat",
|
||||
@@ -76,9 +81,9 @@ 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 shared.Commit, rule Rule) (shared.AnalyzedCommit, bool, error) {
|
||||
|
||||
analyzed := AnalyzedCommit{
|
||||
analyzed := shared.AnalyzedCommit{
|
||||
Commit: commit,
|
||||
Tag: rule.Tag,
|
||||
TagString: rule.TagString,
|
||||
@@ -89,13 +94,13 @@ func (a *angular) analyze(commit gitutil.Commit, rule Rule) (AnalyzedCommit, boo
|
||||
if len(matches) >= 1 {
|
||||
if len(matches[0]) >= 3 {
|
||||
|
||||
analyzed.Scope = Scope(matches[0][2])
|
||||
analyzed.Scope = shared.Scope(matches[0][2])
|
||||
|
||||
message := strings.Join(matches[0][3:], "")
|
||||
if !strings.Contains(message, "BREAKING CHANGE:") {
|
||||
analyzed.ParsedMessage = strings.Trim(message, " ")
|
||||
|
||||
log.Tracef("%s: found %s", commit.Message, rule.Tag)
|
||||
a.log.Tracef("%s: found %s", commit.Message, rule.Tag)
|
||||
return analyzed, false, nil
|
||||
}
|
||||
breakingChange := strings.SplitN(message, "BREAKING CHANGE:", 2)
|
||||
@@ -103,11 +108,11 @@ func (a *angular) analyze(commit gitutil.Commit, rule Rule) (AnalyzedCommit, boo
|
||||
analyzed.ParsedMessage = strings.Trim(breakingChange[0], " ")
|
||||
analyzed.ParsedBreakingChangeMessage = strings.Trim(breakingChange[1], " ")
|
||||
|
||||
log.Tracef(" %s, BREAKING CHANGE found", commit.Message)
|
||||
a.log.Tracef(" %s, BREAKING CHANGE found", commit.Message)
|
||||
return analyzed, true, nil
|
||||
}
|
||||
}
|
||||
log.Tracef("%s does not match %s, skip", commit.Message, rule.Tag)
|
||||
a.log.Tracef("%s does not match %s, skip", commit.Message, rule.Tag)
|
||||
return analyzed, false, fmt.Errorf("not found")
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/Nightapes/go-semantic-release/internal/analyzer"
|
||||
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
||||
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -13,15 +13,15 @@ func TestAngular(t *testing.T) {
|
||||
|
||||
testConfigs := []struct {
|
||||
testCase string
|
||||
commits []gitutil.Commit
|
||||
analyzedCommits map[analyzer.Release][]analyzer.AnalyzedCommit
|
||||
commits []shared.Commit
|
||||
analyzedCommits map[shared.Release][]shared.AnalyzedCommit
|
||||
}{
|
||||
{
|
||||
testCase: "feat",
|
||||
analyzedCommits: map[analyzer.Release][]analyzer.AnalyzedCommit{
|
||||
"minor": []analyzer.AnalyzedCommit{
|
||||
analyzer.AnalyzedCommit{
|
||||
Commit: gitutil.Commit{
|
||||
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||
"minor": []shared.AnalyzedCommit{
|
||||
shared.AnalyzedCommit{
|
||||
Commit: shared.Commit{
|
||||
Message: "feat(internal/changelog): my first commit",
|
||||
Author: "me",
|
||||
Hash: "12345667",
|
||||
@@ -33,12 +33,12 @@ func TestAngular(t *testing.T) {
|
||||
Print: true,
|
||||
},
|
||||
},
|
||||
"major": []analyzer.AnalyzedCommit{},
|
||||
"patch": []analyzer.AnalyzedCommit{},
|
||||
"none": []analyzer.AnalyzedCommit{},
|
||||
"major": []shared.AnalyzedCommit{},
|
||||
"patch": []shared.AnalyzedCommit{},
|
||||
"none": []shared.AnalyzedCommit{},
|
||||
},
|
||||
commits: []gitutil.Commit{
|
||||
gitutil.Commit{
|
||||
commits: []shared.Commit{
|
||||
shared.Commit{
|
||||
Message: "feat(internal/changelog): my first commit",
|
||||
Author: "me",
|
||||
Hash: "12345667",
|
||||
@@ -47,10 +47,10 @@ func TestAngular(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testCase: "feat breaking change",
|
||||
analyzedCommits: map[analyzer.Release][]analyzer.AnalyzedCommit{
|
||||
"minor": []analyzer.AnalyzedCommit{
|
||||
analyzer.AnalyzedCommit{
|
||||
Commit: gitutil.Commit{
|
||||
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||
"minor": []shared.AnalyzedCommit{
|
||||
shared.AnalyzedCommit{
|
||||
Commit: shared.Commit{
|
||||
Message: "feat(internal/changelog): my first commit",
|
||||
Author: "me",
|
||||
Hash: "12345667",
|
||||
@@ -62,9 +62,9 @@ func TestAngular(t *testing.T) {
|
||||
Print: true,
|
||||
},
|
||||
},
|
||||
"major": []analyzer.AnalyzedCommit{
|
||||
analyzer.AnalyzedCommit{
|
||||
Commit: gitutil.Commit{
|
||||
"major": []shared.AnalyzedCommit{
|
||||
shared.AnalyzedCommit{
|
||||
Commit: shared.Commit{
|
||||
Message: "feat(internal/changelog): my first break BREAKING CHANGE: change api to v2",
|
||||
Author: "me",
|
||||
Hash: "12345668",
|
||||
@@ -77,16 +77,16 @@ func TestAngular(t *testing.T) {
|
||||
ParsedBreakingChangeMessage: "change api to v2",
|
||||
},
|
||||
},
|
||||
"patch": []analyzer.AnalyzedCommit{},
|
||||
"none": []analyzer.AnalyzedCommit{},
|
||||
"patch": []shared.AnalyzedCommit{},
|
||||
"none": []shared.AnalyzedCommit{},
|
||||
},
|
||||
commits: []gitutil.Commit{
|
||||
gitutil.Commit{
|
||||
commits: []shared.Commit{
|
||||
shared.Commit{
|
||||
Message: "feat(internal/changelog): my first commit",
|
||||
Author: "me",
|
||||
Hash: "12345667",
|
||||
},
|
||||
gitutil.Commit{
|
||||
shared.Commit{
|
||||
Message: "feat(internal/changelog): my first break BREAKING CHANGE: change api to v2",
|
||||
Author: "me",
|
||||
Hash: "12345668",
|
||||
@@ -95,14 +95,14 @@ func TestAngular(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testCase: "invalid",
|
||||
analyzedCommits: map[analyzer.Release][]analyzer.AnalyzedCommit{
|
||||
"minor": []analyzer.AnalyzedCommit{},
|
||||
"major": []analyzer.AnalyzedCommit{},
|
||||
"patch": []analyzer.AnalyzedCommit{},
|
||||
"none": []analyzer.AnalyzedCommit{},
|
||||
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||
"minor": []shared.AnalyzedCommit{},
|
||||
"major": []shared.AnalyzedCommit{},
|
||||
"patch": []shared.AnalyzedCommit{},
|
||||
"none": []shared.AnalyzedCommit{},
|
||||
},
|
||||
commits: []gitutil.Commit{
|
||||
gitutil.Commit{
|
||||
commits: []shared.Commit{
|
||||
shared.Commit{
|
||||
Message: "internal/changelog: my first commit",
|
||||
Author: "me",
|
||||
Hash: "12345667",
|
||||
@@ -111,10 +111,10 @@ func TestAngular(t *testing.T) {
|
||||
},
|
||||
{
|
||||
testCase: "feat and build",
|
||||
analyzedCommits: map[analyzer.Release][]analyzer.AnalyzedCommit{
|
||||
"minor": []analyzer.AnalyzedCommit{
|
||||
analyzer.AnalyzedCommit{
|
||||
Commit: gitutil.Commit{
|
||||
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||
"minor": []shared.AnalyzedCommit{
|
||||
shared.AnalyzedCommit{
|
||||
Commit: shared.Commit{
|
||||
Message: "feat(internal/changelog): my first commit",
|
||||
Author: "me",
|
||||
Hash: "12345667",
|
||||
@@ -126,9 +126,9 @@ func TestAngular(t *testing.T) {
|
||||
Print: true,
|
||||
},
|
||||
},
|
||||
"none": []analyzer.AnalyzedCommit{
|
||||
analyzer.AnalyzedCommit{
|
||||
Commit: gitutil.Commit{
|
||||
"none": []shared.AnalyzedCommit{
|
||||
shared.AnalyzedCommit{
|
||||
Commit: shared.Commit{
|
||||
Message: "build(internal/changelog): my first build",
|
||||
Author: "me",
|
||||
Hash: "12345668",
|
||||
@@ -141,16 +141,16 @@ func TestAngular(t *testing.T) {
|
||||
ParsedBreakingChangeMessage: "",
|
||||
},
|
||||
},
|
||||
"patch": []analyzer.AnalyzedCommit{},
|
||||
"major": []analyzer.AnalyzedCommit{},
|
||||
"patch": []shared.AnalyzedCommit{},
|
||||
"major": []shared.AnalyzedCommit{},
|
||||
},
|
||||
commits: []gitutil.Commit{
|
||||
gitutil.Commit{
|
||||
commits: []shared.Commit{
|
||||
shared.Commit{
|
||||
Message: "feat(internal/changelog): my first commit",
|
||||
Author: "me",
|
||||
Hash: "12345667",
|
||||
},
|
||||
gitutil.Commit{
|
||||
shared.Commit{
|
||||
Message: "build(internal/changelog): my first build",
|
||||
Author: "me",
|
||||
Hash: "12345668",
|
||||
|
||||
Reference in New Issue
Block a user