Merge pull request #10 from Nightapes/fixes

Fixes
This commit is contained in:
Felix Wiedmann
2019-08-11 23:02:12 +02:00
committed by GitHub
17 changed files with 250 additions and 254 deletions

View File

@@ -45,13 +45,13 @@ var changelogCmd = &cobra.Command{
return err return err
} }
releaseVersion, commits, err := s.GetNextVersion(provider, force) releaseVersion, err := s.GetNextVersion(provider, force)
if err != nil { if err != nil {
return err return err
} }
log.Debugf("Found %d commits till last release", len(commits)) log.Debugf("Found %d commits till last release", len(releaseVersion.Commits))
generatedChangelog, err := s.GetChangelog(commits, releaseVersion) generatedChangelog, err := s.GetChangelog(releaseVersion)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -43,7 +43,7 @@ var nextCmd = &cobra.Command{
return nil return nil
} }
releaseVersion, _, err := s.GetNextVersion(provider, force) releaseVersion, err := s.GetNextVersion(provider, force)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -31,11 +31,7 @@ func Execute(version string) {
} }
func init() { func init() {
currentDir, err := os.Getwd() rootCmd.PersistentFlags().StringP("repository", "r", "./", "Path to repository")
if err != nil {
panic(err)
}
rootCmd.PersistentFlags().StringP("repository", "r", currentDir, "Path to repository")
rootCmd.PersistentFlags().StringP("loglevel", "l", "error", "Set loglevel") rootCmd.PersistentFlags().StringP("loglevel", "l", "error", "Set loglevel")
rootCmd.PersistentFlags().StringP("config", "c", ".release.yml", "Path to config file") rootCmd.PersistentFlags().StringP("config", "c", ".release.yml", "Path to config file")
rootCmd.PersistentFlags().Bool("no-cache", false, "Ignore cache, don't use in ci build") rootCmd.PersistentFlags().Bool("no-cache", false, "Ignore cache, don't use in ci build")

View File

@@ -4,47 +4,30 @@ package analyzer
import ( import (
"fmt" "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" "github.com/Nightapes/go-semantic-release/pkg/config"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
//Analyzer struct //Analyzer struct
type Analyzer struct { type Analyzer struct {
analyzeCommit analyzeCommit analyzeCommits analyzeCommits
Config config.ChangelogConfig Config config.ChangelogConfig
} }
//Release types, like major
type Release string
//Scope of the commit, like feat, fix,..
type Scope string
//Rule for commits //Rule for commits
type Rule struct { type Rule struct {
Tag string Tag string
TagString string TagString string
Release Release Release shared.Release
Changelog bool Changelog bool
} }
type analyzeCommit interface { type analyzeCommits interface {
analyze(commit gitutil.Commit, tag Rule) (AnalyzedCommit, bool, error) analyze(commit shared.Commit, tag Rule) (shared.AnalyzedCommit, bool, error)
getRules() []Rule 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 //New Analyzer struct for given commit format
func New(format string, config config.ChangelogConfig) (*Analyzer, error) { func New(format string, config config.ChangelogConfig) (*Analyzer, error) {
analyzer := &Analyzer{ analyzer := &Analyzer{
@@ -52,9 +35,9 @@ func New(format string, config config.ChangelogConfig) (*Analyzer, error) {
} }
switch format { switch format {
case "angular": case ANGULAR:
log.Debugf("Commit format set to angular") analyzer.analyzeCommits = newAngular()
analyzer.analyzeCommit = newAngular() log.Debugf("Commit format set to %s", ANGULAR)
default: default:
return nil, fmt.Errorf("invalid commit format: %s", format) 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 // GetRules from current mode
func (a *Analyzer) GetRules() []Rule { func (a *Analyzer) GetRules() []Rule {
return a.analyzeCommit.getRules() return a.analyzeCommits.getRules()
} }
// Analyze commits and return commits splitted by major,minor,patch // 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 := make(map[shared.Release][]shared.AnalyzedCommit)
analyzedCommits["major"] = make([]AnalyzedCommit, 0) analyzedCommits["major"] = make([]shared.AnalyzedCommit, 0)
analyzedCommits["minor"] = make([]AnalyzedCommit, 0) analyzedCommits["minor"] = make([]shared.AnalyzedCommit, 0)
analyzedCommits["patch"] = make([]AnalyzedCommit, 0) analyzedCommits["patch"] = make([]shared.AnalyzedCommit, 0)
analyzedCommits["none"] = make([]AnalyzedCommit, 0) analyzedCommits["none"] = make([]shared.AnalyzedCommit, 0)
for _, commit := range commits { for _, commit := range commits {
for _, rule := range a.analyzeCommit.getRules() { for _, rule := range a.analyzeCommits.getRules() {
analyzedCommit, hasBreakingChange, err := a.analyzeCommit.analyze(commit, rule) analyzedCommit, hasBreakingChange, err := a.analyzeCommits.analyze(commit, rule)
if err == nil { if err == nil {
if a.Config.PrintAll { if a.Config.PrintAll {
analyzedCommit.Print = true analyzedCommit.Print = true

View File

@@ -8,17 +8,22 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/Nightapes/go-semantic-release/internal/gitutil" "github.com/Nightapes/go-semantic-release/internal/shared"
) )
type angular struct { type angular struct {
rules []Rule rules []Rule
regex string regex string
log *log.Entry
} }
// ANGULAR identifer
const ANGULAR = "angular"
func newAngular() *angular { func newAngular() *angular {
return &angular{ return &angular{
regex: `(TAG)(?:\((.*)\))?: (.*)`, regex: `(TAG)(?:\((.*)\))?: (.*)`,
log: log.WithField("analyzer", ANGULAR),
rules: []Rule{ rules: []Rule{
{ {
Tag: "feat", Tag: "feat",
@@ -76,9 +81,9 @@ func (a *angular) getRules() []Rule {
return a.rules 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, Commit: commit,
Tag: rule.Tag, Tag: rule.Tag,
TagString: rule.TagString, 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) >= 1 {
if len(matches[0]) >= 3 { if len(matches[0]) >= 3 {
analyzed.Scope = Scope(matches[0][2]) analyzed.Scope = shared.Scope(matches[0][2])
message := strings.Join(matches[0][3:], "") message := strings.Join(matches[0][3:], "")
if !strings.Contains(message, "BREAKING CHANGE:") { if !strings.Contains(message, "BREAKING CHANGE:") {
analyzed.ParsedMessage = strings.Trim(message, " ") 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 return analyzed, false, nil
} }
breakingChange := strings.SplitN(message, "BREAKING CHANGE:", 2) 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.ParsedMessage = strings.Trim(breakingChange[0], " ")
analyzed.ParsedBreakingChangeMessage = strings.Trim(breakingChange[1], " ") 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 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") return analyzed, false, fmt.Errorf("not found")
} }

View File

@@ -4,7 +4,7 @@ import (
"testing" "testing"
"github.com/Nightapes/go-semantic-release/internal/analyzer" "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/Nightapes/go-semantic-release/pkg/config"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@@ -13,15 +13,15 @@ func TestAngular(t *testing.T) {
testConfigs := []struct { testConfigs := []struct {
testCase string testCase string
commits []gitutil.Commit commits []shared.Commit
analyzedCommits map[analyzer.Release][]analyzer.AnalyzedCommit analyzedCommits map[shared.Release][]shared.AnalyzedCommit
}{ }{
{ {
testCase: "feat", testCase: "feat",
analyzedCommits: map[analyzer.Release][]analyzer.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": []analyzer.AnalyzedCommit{ "minor": []shared.AnalyzedCommit{
analyzer.AnalyzedCommit{ shared.AnalyzedCommit{
Commit: gitutil.Commit{ Commit: shared.Commit{
Message: "feat(internal/changelog): my first commit", Message: "feat(internal/changelog): my first commit",
Author: "me", Author: "me",
Hash: "12345667", Hash: "12345667",
@@ -33,12 +33,12 @@ func TestAngular(t *testing.T) {
Print: true, Print: true,
}, },
}, },
"major": []analyzer.AnalyzedCommit{}, "major": []shared.AnalyzedCommit{},
"patch": []analyzer.AnalyzedCommit{}, "patch": []shared.AnalyzedCommit{},
"none": []analyzer.AnalyzedCommit{}, "none": []shared.AnalyzedCommit{},
}, },
commits: []gitutil.Commit{ commits: []shared.Commit{
gitutil.Commit{ shared.Commit{
Message: "feat(internal/changelog): my first commit", Message: "feat(internal/changelog): my first commit",
Author: "me", Author: "me",
Hash: "12345667", Hash: "12345667",
@@ -47,10 +47,10 @@ func TestAngular(t *testing.T) {
}, },
{ {
testCase: "feat breaking change", testCase: "feat breaking change",
analyzedCommits: map[analyzer.Release][]analyzer.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": []analyzer.AnalyzedCommit{ "minor": []shared.AnalyzedCommit{
analyzer.AnalyzedCommit{ shared.AnalyzedCommit{
Commit: gitutil.Commit{ Commit: shared.Commit{
Message: "feat(internal/changelog): my first commit", Message: "feat(internal/changelog): my first commit",
Author: "me", Author: "me",
Hash: "12345667", Hash: "12345667",
@@ -62,9 +62,9 @@ func TestAngular(t *testing.T) {
Print: true, Print: true,
}, },
}, },
"major": []analyzer.AnalyzedCommit{ "major": []shared.AnalyzedCommit{
analyzer.AnalyzedCommit{ shared.AnalyzedCommit{
Commit: gitutil.Commit{ Commit: shared.Commit{
Message: "feat(internal/changelog): my first break BREAKING CHANGE: change api to v2", Message: "feat(internal/changelog): my first break BREAKING CHANGE: change api to v2",
Author: "me", Author: "me",
Hash: "12345668", Hash: "12345668",
@@ -77,16 +77,16 @@ func TestAngular(t *testing.T) {
ParsedBreakingChangeMessage: "change api to v2", ParsedBreakingChangeMessage: "change api to v2",
}, },
}, },
"patch": []analyzer.AnalyzedCommit{}, "patch": []shared.AnalyzedCommit{},
"none": []analyzer.AnalyzedCommit{}, "none": []shared.AnalyzedCommit{},
}, },
commits: []gitutil.Commit{ commits: []shared.Commit{
gitutil.Commit{ shared.Commit{
Message: "feat(internal/changelog): my first commit", Message: "feat(internal/changelog): my first commit",
Author: "me", Author: "me",
Hash: "12345667", Hash: "12345667",
}, },
gitutil.Commit{ shared.Commit{
Message: "feat(internal/changelog): my first break BREAKING CHANGE: change api to v2", Message: "feat(internal/changelog): my first break BREAKING CHANGE: change api to v2",
Author: "me", Author: "me",
Hash: "12345668", Hash: "12345668",
@@ -95,14 +95,14 @@ func TestAngular(t *testing.T) {
}, },
{ {
testCase: "invalid", testCase: "invalid",
analyzedCommits: map[analyzer.Release][]analyzer.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": []analyzer.AnalyzedCommit{}, "minor": []shared.AnalyzedCommit{},
"major": []analyzer.AnalyzedCommit{}, "major": []shared.AnalyzedCommit{},
"patch": []analyzer.AnalyzedCommit{}, "patch": []shared.AnalyzedCommit{},
"none": []analyzer.AnalyzedCommit{}, "none": []shared.AnalyzedCommit{},
}, },
commits: []gitutil.Commit{ commits: []shared.Commit{
gitutil.Commit{ shared.Commit{
Message: "internal/changelog: my first commit", Message: "internal/changelog: my first commit",
Author: "me", Author: "me",
Hash: "12345667", Hash: "12345667",
@@ -111,10 +111,10 @@ func TestAngular(t *testing.T) {
}, },
{ {
testCase: "feat and build", testCase: "feat and build",
analyzedCommits: map[analyzer.Release][]analyzer.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": []analyzer.AnalyzedCommit{ "minor": []shared.AnalyzedCommit{
analyzer.AnalyzedCommit{ shared.AnalyzedCommit{
Commit: gitutil.Commit{ Commit: shared.Commit{
Message: "feat(internal/changelog): my first commit", Message: "feat(internal/changelog): my first commit",
Author: "me", Author: "me",
Hash: "12345667", Hash: "12345667",
@@ -126,9 +126,9 @@ func TestAngular(t *testing.T) {
Print: true, Print: true,
}, },
}, },
"none": []analyzer.AnalyzedCommit{ "none": []shared.AnalyzedCommit{
analyzer.AnalyzedCommit{ shared.AnalyzedCommit{
Commit: gitutil.Commit{ Commit: shared.Commit{
Message: "build(internal/changelog): my first build", Message: "build(internal/changelog): my first build",
Author: "me", Author: "me",
Hash: "12345668", Hash: "12345668",
@@ -141,16 +141,16 @@ func TestAngular(t *testing.T) {
ParsedBreakingChangeMessage: "", ParsedBreakingChangeMessage: "",
}, },
}, },
"patch": []analyzer.AnalyzedCommit{}, "patch": []shared.AnalyzedCommit{},
"major": []analyzer.AnalyzedCommit{}, "major": []shared.AnalyzedCommit{},
}, },
commits: []gitutil.Commit{ commits: []shared.Commit{
gitutil.Commit{ shared.Commit{
Message: "feat(internal/changelog): my first commit", Message: "feat(internal/changelog): my first commit",
Author: "me", Author: "me",
Hash: "12345667", Hash: "12345667",
}, },
gitutil.Commit{ shared.Commit{
Message: "build(internal/changelog): my first build", Message: "build(internal/changelog): my first build",
Author: "me", Author: "me",
Hash: "12345668", Hash: "12345668",

View File

@@ -2,52 +2,35 @@
package cache package cache
import ( import (
log "github.com/sirupsen/logrus"
"io/ioutil" "io/ioutil"
"path" "path"
log "github.com/sirupsen/logrus"
"github.com/Masterminds/semver" "github.com/Masterminds/semver"
"github.com/Nightapes/go-semantic-release/internal/shared" "github.com/Nightapes/go-semantic-release/internal/shared"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
// ReleaseVersion struct
type ReleaseVersion struct {
Last ReleaseVersionEntry `yaml:"last"`
Next ReleaseVersionEntry `yaml:"next"`
Branch string `yaml:"branch"`
Draft bool `yaml:"draft"`
}
//ReleaseVersionEntry struct
type ReleaseVersionEntry struct {
Commit string `yaml:"commit"`
Version string `yaml:"version"`
}
// Write version into .version // Write version into .version
func Write(repository string, releaseVersion shared.ReleaseVersion) error { func Write(repository string, releaseVersion shared.ReleaseVersion) error {
completePath := path.Join(path.Dir(repository), ".version") completePath := path.Join(path.Dir(repository), ".version")
toCache := &ReleaseVersion{ if releaseVersion.Last.Version != nil {
Next: ReleaseVersionEntry{ releaseVersion.Last.VersionString = releaseVersion.Last.Version.String()
Commit: releaseVersion.Next.Commit,
Version: releaseVersion.Next.Version.String(),
},
Last: ReleaseVersionEntry{
Commit: releaseVersion.Last.Commit,
Version: releaseVersion.Last.Version.String(),
},
Branch: releaseVersion.Branch,
Draft: releaseVersion.Draft,
} }
data, err := yaml.Marshal(toCache) if releaseVersion.Next.Version != nil {
releaseVersion.Next.VersionString = releaseVersion.Next.Version.String()
}
//toCache := &ReleaseVersion(releaseVersion)
data, err := yaml.Marshal(releaseVersion)
if err != nil { if err != nil {
return err return err
} }
log.Infof("Save %s with hash %s to cache", releaseVersion.Next.Version.String(), releaseVersion.Next.Commit) log.Infof("Save %s with hash %s to cache %s", releaseVersion.Next.Version.String(), releaseVersion.Next.Commit, completePath)
return ioutil.WriteFile(completePath, data, 0644) return ioutil.WriteFile(completePath, data, 0644)
} }
@@ -57,37 +40,26 @@ func Read(repository string) (*shared.ReleaseVersion, error) {
content, err := ioutil.ReadFile(completePath) content, err := ioutil.ReadFile(completePath)
if err != nil { if err != nil {
return &shared.ReleaseVersion{}, err log.Warnf("Could not read cache %s, will ignore cache", completePath)
return &shared.ReleaseVersion{}, nil
} }
var parsedContent ReleaseVersion var parsedContent shared.ReleaseVersion
err = yaml.Unmarshal(content, &parsedContent) err = yaml.Unmarshal(content, &parsedContent)
if err != nil { if err != nil {
return &shared.ReleaseVersion{}, err return &shared.ReleaseVersion{}, err
} }
nextVersion, err := semver.NewVersion(parsedContent.Next.Version) parsedContent.Next.Version, err = semver.NewVersion(parsedContent.Next.VersionString)
if err != nil { if err != nil {
return nil, err return nil, err
} }
lastVersion, err := semver.NewVersion(parsedContent.Last.Version) parsedContent.Last.Version, err = semver.NewVersion(parsedContent.Last.VersionString)
if err != nil { if err != nil {
return nil, err return nil, err
} }
releaseVersion := &shared.ReleaseVersion{
Next: shared.ReleaseVersionEntry{
Commit: parsedContent.Next.Commit,
Version: nextVersion,
},
Last: shared.ReleaseVersionEntry{
Commit: parsedContent.Last.Commit,
Version: lastVersion,
},
Branch: parsedContent.Branch,
Draft: parsedContent.Draft,
}
log.Infof("Found cache, will return cached version %s", parsedContent.Next.Version) log.Infof("Found cache, will return cached version %s", parsedContent.Next.Version)
return releaseVersion, nil return &parsedContent, nil
} }

View File

@@ -14,8 +14,9 @@ import (
func TestReadCacheNotFound(t *testing.T) { func TestReadCacheNotFound(t *testing.T) {
_, err := cache.Read("notfound/dir") resp, err := cache.Read("notfound/dir")
assert.Errorf(t, err, "Read non exsiting file") assert.NoErrorf(t, err, "Read non exsiting file")
assert.NotNil(t, resp)
} }
@@ -43,15 +44,34 @@ func TestWriteAndReadCache(t *testing.T) {
content := shared.ReleaseVersion{ content := shared.ReleaseVersion{
Last: shared.ReleaseVersionEntry{ Last: shared.ReleaseVersionEntry{
Commit: "12345", Commit: "12345",
Version: createVersion("1.0.0"), Version: createVersion("1.0.0"),
VersionString: "1.0.0",
}, },
Next: shared.ReleaseVersionEntry{ Next: shared.ReleaseVersionEntry{
Commit: "12346", Commit: "12346",
Version: createVersion("1.1.0"), Version: createVersion("1.1.0"),
VersionString: "1.1.0",
}, },
Branch: "master", Branch: "master",
Draft: true, Draft: true,
Commits: map[shared.Release][]shared.AnalyzedCommit{
"major": []shared.AnalyzedCommit{
shared.AnalyzedCommit{
Commit: shared.Commit{
Message: "Message",
Author: "Author",
Hash: "Hash",
},
ParsedMessage: "add gitlab as relase option",
Scope: "releaser",
ParsedBreakingChangeMessage: "",
Tag: "feat",
TagString: "Features",
Print: true,
},
},
},
} }
defer os.RemoveAll(dir) defer os.RemoveAll(dir)

View File

@@ -5,7 +5,7 @@ import (
"strings" "strings"
"github.com/Masterminds/semver" "github.com/Masterminds/semver"
"github.com/Nightapes/go-semantic-release/internal/analyzer" "github.com/Nightapes/go-semantic-release/internal/shared"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@@ -40,7 +40,7 @@ func (c *Calculator) IncPrerelease(preReleaseType string, version *semver.Versio
} }
//CalculateNewVersion from given commits and lastversion //CalculateNewVersion from given commits and lastversion
func (c *Calculator) CalculateNewVersion(commits map[analyzer.Release][]analyzer.AnalyzedCommit, lastVersion *semver.Version, releaseType string, firstRelease bool) (semver.Version, bool) { func (c *Calculator) CalculateNewVersion(commits map[shared.Release][]shared.AnalyzedCommit, lastVersion *semver.Version, releaseType string, firstRelease bool) (semver.Version, bool) {
switch releaseType { switch releaseType {
case "beta", "alpha": case "beta", "alpha":
if len(commits["major"]) > 0 || len(commits["minor"]) > 0 || len(commits["patch"]) > 0 { if len(commits["major"]) > 0 || len(commits["minor"]) > 0 || len(commits["patch"]) > 0 {

View File

@@ -4,8 +4,8 @@ import (
"testing" "testing"
"github.com/Masterminds/semver" "github.com/Masterminds/semver"
"github.com/Nightapes/go-semantic-release/internal/analyzer"
"github.com/Nightapes/go-semantic-release/internal/calculator" "github.com/Nightapes/go-semantic-release/internal/calculator"
"github.com/Nightapes/go-semantic-release/internal/shared"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@@ -74,20 +74,20 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
nextVersion string nextVersion string
isDraft bool isDraft bool
isFirst bool isFirst bool
analyzedCommits map[analyzer.Release][]analyzer.AnalyzedCommit analyzedCommits map[shared.Release][]shared.AnalyzedCommit
}{ }{
{ {
testCase: "version with preRelease alpha", testCase: "version with preRelease alpha",
releaseType: "alpha", releaseType: "alpha",
lastVersion: createVersion("1.0.0"), lastVersion: createVersion("1.0.0"),
nextVersion: "1.0.0-alpha.0", nextVersion: "1.0.0-alpha.0",
analyzedCommits: map[analyzer.Release][]analyzer.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"major": []analyzer.AnalyzedCommit{}, "major": []shared.AnalyzedCommit{},
"minor": []analyzer.AnalyzedCommit{ "minor": []shared.AnalyzedCommit{
analyzer.AnalyzedCommit{}, shared.AnalyzedCommit{},
}, },
"patch": []analyzer.AnalyzedCommit{}, "patch": []shared.AnalyzedCommit{},
"none": []analyzer.AnalyzedCommit{}, "none": []shared.AnalyzedCommit{},
}, },
isFirst: false, isFirst: false,
isDraft: true, isDraft: true,
@@ -97,13 +97,13 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
releaseType: "beta", releaseType: "beta",
lastVersion: createVersion("1.0.0"), lastVersion: createVersion("1.0.0"),
nextVersion: "1.0.0-beta.0", nextVersion: "1.0.0-beta.0",
analyzedCommits: map[analyzer.Release][]analyzer.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"major": []analyzer.AnalyzedCommit{}, "major": []shared.AnalyzedCommit{},
"minor": []analyzer.AnalyzedCommit{ "minor": []shared.AnalyzedCommit{
analyzer.AnalyzedCommit{}, shared.AnalyzedCommit{},
}, },
"patch": []analyzer.AnalyzedCommit{}, "patch": []shared.AnalyzedCommit{},
"none": []analyzer.AnalyzedCommit{}, "none": []shared.AnalyzedCommit{},
}, },
isFirst: false, isFirst: false,
isDraft: true, isDraft: true,
@@ -113,11 +113,11 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
releaseType: "alpha", releaseType: "alpha",
lastVersion: createVersion("1.0.0"), lastVersion: createVersion("1.0.0"),
nextVersion: "1.0.0", nextVersion: "1.0.0",
analyzedCommits: map[analyzer.Release][]analyzer.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"major": []analyzer.AnalyzedCommit{}, "major": []shared.AnalyzedCommit{},
"minor": []analyzer.AnalyzedCommit{}, "minor": []shared.AnalyzedCommit{},
"patch": []analyzer.AnalyzedCommit{}, "patch": []shared.AnalyzedCommit{},
"none": []analyzer.AnalyzedCommit{}, "none": []shared.AnalyzedCommit{},
}, },
isFirst: false, isFirst: false,
isDraft: false, isDraft: false,
@@ -127,11 +127,11 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
releaseType: "release", releaseType: "release",
lastVersion: createVersion("1.0.0"), lastVersion: createVersion("1.0.0"),
nextVersion: "1.0.0", nextVersion: "1.0.0",
analyzedCommits: map[analyzer.Release][]analyzer.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"major": []analyzer.AnalyzedCommit{analyzer.AnalyzedCommit{}}, "major": []shared.AnalyzedCommit{shared.AnalyzedCommit{}},
"minor": []analyzer.AnalyzedCommit{}, "minor": []shared.AnalyzedCommit{},
"patch": []analyzer.AnalyzedCommit{}, "patch": []shared.AnalyzedCommit{},
"none": []analyzer.AnalyzedCommit{}, "none": []shared.AnalyzedCommit{},
}, },
isFirst: true, isFirst: true,
isDraft: false, isDraft: false,
@@ -141,11 +141,11 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
releaseType: "rc", releaseType: "rc",
lastVersion: createVersion("1.0.0"), lastVersion: createVersion("1.0.0"),
nextVersion: "1.0.0-rc.0", nextVersion: "1.0.0-rc.0",
analyzedCommits: map[analyzer.Release][]analyzer.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"major": []analyzer.AnalyzedCommit{analyzer.AnalyzedCommit{}}, "major": []shared.AnalyzedCommit{shared.AnalyzedCommit{}},
"minor": []analyzer.AnalyzedCommit{analyzer.AnalyzedCommit{}}, "minor": []shared.AnalyzedCommit{shared.AnalyzedCommit{}},
"patch": []analyzer.AnalyzedCommit{analyzer.AnalyzedCommit{}}, "patch": []shared.AnalyzedCommit{shared.AnalyzedCommit{}},
"none": []analyzer.AnalyzedCommit{}, "none": []shared.AnalyzedCommit{},
}, },
isFirst: false, isFirst: false,
isDraft: false, isDraft: false,
@@ -155,11 +155,11 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
releaseType: "rc", releaseType: "rc",
lastVersion: createVersion("1.0.0-rc.0"), lastVersion: createVersion("1.0.0-rc.0"),
nextVersion: "1.0.0-rc.1", nextVersion: "1.0.0-rc.1",
analyzedCommits: map[analyzer.Release][]analyzer.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"major": []analyzer.AnalyzedCommit{}, "major": []shared.AnalyzedCommit{},
"minor": []analyzer.AnalyzedCommit{analyzer.AnalyzedCommit{}}, "minor": []shared.AnalyzedCommit{shared.AnalyzedCommit{}},
"patch": []analyzer.AnalyzedCommit{analyzer.AnalyzedCommit{}}, "patch": []shared.AnalyzedCommit{shared.AnalyzedCommit{}},
"none": []analyzer.AnalyzedCommit{}, "none": []shared.AnalyzedCommit{},
}, },
isFirst: false, isFirst: false,
isDraft: false, isDraft: false,
@@ -169,11 +169,11 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
releaseType: "release", releaseType: "release",
lastVersion: createVersion("1.0.0"), lastVersion: createVersion("1.0.0"),
nextVersion: "2.0.0", nextVersion: "2.0.0",
analyzedCommits: map[analyzer.Release][]analyzer.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"major": []analyzer.AnalyzedCommit{analyzer.AnalyzedCommit{}}, "major": []shared.AnalyzedCommit{shared.AnalyzedCommit{}},
"minor": []analyzer.AnalyzedCommit{analyzer.AnalyzedCommit{}}, "minor": []shared.AnalyzedCommit{shared.AnalyzedCommit{}},
"patch": []analyzer.AnalyzedCommit{analyzer.AnalyzedCommit{}}, "patch": []shared.AnalyzedCommit{shared.AnalyzedCommit{}},
"none": []analyzer.AnalyzedCommit{}, "none": []shared.AnalyzedCommit{},
}, },
isFirst: false, isFirst: false,
isDraft: false, isDraft: false,
@@ -183,11 +183,11 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
releaseType: "release", releaseType: "release",
lastVersion: createVersion("1.0.0"), lastVersion: createVersion("1.0.0"),
nextVersion: "1.1.0", nextVersion: "1.1.0",
analyzedCommits: map[analyzer.Release][]analyzer.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"major": []analyzer.AnalyzedCommit{}, "major": []shared.AnalyzedCommit{},
"minor": []analyzer.AnalyzedCommit{analyzer.AnalyzedCommit{}}, "minor": []shared.AnalyzedCommit{shared.AnalyzedCommit{}},
"patch": []analyzer.AnalyzedCommit{analyzer.AnalyzedCommit{}}, "patch": []shared.AnalyzedCommit{shared.AnalyzedCommit{}},
"none": []analyzer.AnalyzedCommit{}, "none": []shared.AnalyzedCommit{},
}, },
isFirst: false, isFirst: false,
isDraft: false, isDraft: false,
@@ -197,11 +197,11 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
releaseType: "release", releaseType: "release",
lastVersion: createVersion("1.0.0"), lastVersion: createVersion("1.0.0"),
nextVersion: "1.0.1", nextVersion: "1.0.1",
analyzedCommits: map[analyzer.Release][]analyzer.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"major": []analyzer.AnalyzedCommit{}, "major": []shared.AnalyzedCommit{},
"minor": []analyzer.AnalyzedCommit{}, "minor": []shared.AnalyzedCommit{},
"patch": []analyzer.AnalyzedCommit{analyzer.AnalyzedCommit{}}, "patch": []shared.AnalyzedCommit{shared.AnalyzedCommit{}},
"none": []analyzer.AnalyzedCommit{}, "none": []shared.AnalyzedCommit{},
}, },
isFirst: false, isFirst: false,
isDraft: false, isDraft: false,

View File

@@ -34,8 +34,8 @@ introduced by commit:
` `
type changelogContent struct { type changelogContent struct {
Commits map[string][]analyzer.AnalyzedCommit Commits map[string][]shared.AnalyzedCommit
BreakingChanges []analyzer.AnalyzedCommit BreakingChanges []shared.AnalyzedCommit
Order []string Order []string
Version string Version string
Now time.Time Now time.Time
@@ -49,6 +49,7 @@ type Changelog struct {
config *config.ReleaseConfig config *config.ReleaseConfig
rules []analyzer.Rule rules []analyzer.Rule
releaseTime time.Time releaseTime time.Time
log *log.Entry
} }
//New Changelog struct for generating changelog from commits //New Changelog struct for generating changelog from commits
@@ -57,18 +58,19 @@ func New(config *config.ReleaseConfig, rules []analyzer.Rule, releaseTime time.T
config: config, config: config,
rules: rules, rules: rules,
releaseTime: releaseTime, releaseTime: releaseTime,
log: log.WithField("changelog", config.CommitFormat),
} }
} }
// GenerateChanglog from given commits // GenerateChanglog from given commits
func (c *Changelog) GenerateChanglog(templateConfig shared.ChangelogTemplateConfig, analyzedCommits map[analyzer.Release][]analyzer.AnalyzedCommit) (*shared.GeneratedChangelog, error) { func (c *Changelog) GenerateChanglog(templateConfig shared.ChangelogTemplateConfig, analyzedCommits map[shared.Release][]shared.AnalyzedCommit) (*shared.GeneratedChangelog, error) {
commitsPerScope := map[string][]analyzer.AnalyzedCommit{} commitsPerScope := map[string][]shared.AnalyzedCommit{}
commitsBreakingChange := []analyzer.AnalyzedCommit{} commitsBreakingChange := []shared.AnalyzedCommit{}
order := make([]string, 0) order := make([]string, 0)
for _, rule := range c.rules { for _, rule := range c.rules {
log.Debugf("Add %s to list", rule.TagString) c.log.Tracef("Add %s to list", rule.TagString)
if rule.Changelog || c.config.Changelog.PrintAll { if rule.Changelog || c.config.Changelog.PrintAll {
order = append(order, rule.TagString) order = append(order, rule.TagString)
} }
@@ -82,7 +84,7 @@ func (c *Changelog) GenerateChanglog(templateConfig shared.ChangelogTemplateConf
continue continue
} }
if _, ok := commitsPerScope[commit.TagString]; !ok { if _, ok := commitsPerScope[commit.TagString]; !ok {
commitsPerScope[commit.TagString] = make([]analyzer.AnalyzedCommit, 0) commitsPerScope[commit.TagString] = make([]shared.AnalyzedCommit, 0)
} }
commitsPerScope[commit.TagString] = append(commitsPerScope[commit.TagString], commit) commitsPerScope[commit.TagString] = append(commitsPerScope[commit.TagString], commit)
} }

View File

@@ -5,7 +5,6 @@ import (
"github.com/Nightapes/go-semantic-release/internal/analyzer" "github.com/Nightapes/go-semantic-release/internal/analyzer"
"github.com/Nightapes/go-semantic-release/internal/changelog" "github.com/Nightapes/go-semantic-release/internal/changelog"
"github.com/Nightapes/go-semantic-release/internal/gitutil"
"github.com/Nightapes/go-semantic-release/internal/shared" "github.com/Nightapes/go-semantic-release/internal/shared"
"github.com/Nightapes/go-semantic-release/pkg/config" "github.com/Nightapes/go-semantic-release/pkg/config"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@@ -23,16 +22,16 @@ func TestChangelog(t *testing.T) {
testConfigs := []struct { testConfigs := []struct {
testCase string testCase string
analyzedCommits map[analyzer.Release][]analyzer.AnalyzedCommit analyzedCommits map[shared.Release][]shared.AnalyzedCommit
result *shared.GeneratedChangelog result *shared.GeneratedChangelog
hasError bool hasError bool
}{ }{
{ {
testCase: "feat", testCase: "feat",
analyzedCommits: map[analyzer.Release][]analyzer.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": []analyzer.AnalyzedCommit{ "minor": []shared.AnalyzedCommit{
analyzer.AnalyzedCommit{ shared.AnalyzedCommit{
Commit: gitutil.Commit{ Commit: shared.Commit{
Message: "feat(test): my first commit", Message: "feat(test): my first commit",
Author: "me", Author: "me",
Hash: "12345667", Hash: "12345667",
@@ -53,10 +52,10 @@ func TestChangelog(t *testing.T) {
}, },
{ {
testCase: "feat breaking change", testCase: "feat breaking change",
analyzedCommits: map[analyzer.Release][]analyzer.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": []analyzer.AnalyzedCommit{ "minor": []shared.AnalyzedCommit{
analyzer.AnalyzedCommit{ shared.AnalyzedCommit{
Commit: gitutil.Commit{ Commit: shared.Commit{
Message: "feat(test): my first commit", Message: "feat(test): my first commit",
Author: "me", Author: "me",
Hash: "12345667", Hash: "12345667",
@@ -67,8 +66,8 @@ func TestChangelog(t *testing.T) {
TagString: "Features", TagString: "Features",
Print: true, Print: true,
}, },
analyzer.AnalyzedCommit{ shared.AnalyzedCommit{
Commit: gitutil.Commit{ Commit: shared.Commit{
Message: "feat(test): my first break: BREAKING CHANGE: change api to v2", Message: "feat(test): my first break: BREAKING CHANGE: change api to v2",
Author: "me", Author: "me",
Hash: "12345668", Hash: "12345668",

View File

@@ -10,15 +10,9 @@ import (
"gopkg.in/src-d/go-git.v4" "gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/object" "gopkg.in/src-d/go-git.v4/plumbing/object"
"github.com/Nightapes/go-semantic-release/internal/shared"
) )
// Commit struct
type Commit struct {
Message string
Author string
Hash string
}
// GitUtil struct // GitUtil struct
type GitUtil struct { type GitUtil struct {
Repository *git.Repository Repository *git.Repository
@@ -126,7 +120,7 @@ func (g *GitUtil) GetLastVersion() (*semver.Version, string, error) {
} }
// GetCommits from git hash to HEAD // GetCommits from git hash to HEAD
func (g *GitUtil) GetCommits(lastTagHash string) ([]Commit, error) { func (g *GitUtil) GetCommits(lastTagHash string) ([]shared.Commit, error) {
ref, err := g.Repository.Head() ref, err := g.Repository.Head()
if err != nil { if err != nil {
@@ -138,7 +132,7 @@ func (g *GitUtil) GetCommits(lastTagHash string) ([]Commit, error) {
return nil, err return nil, err
} }
var commits []Commit var commits []shared.Commit
var foundEnd bool var foundEnd bool
err = cIter.ForEach(func(c *object.Commit) error { err = cIter.ForEach(func(c *object.Commit) error {
@@ -149,7 +143,7 @@ func (g *GitUtil) GetCommits(lastTagHash string) ([]Commit, error) {
} }
if !foundEnd { if !foundEnd {
log.Tracef("Found commit with hash %s", c.Hash.String()) log.Tracef("Found commit with hash %s", c.Hash.String())
commit := Commit{ commit := shared.Commit{
Message: c.Message, Message: c.Message,
Author: c.Committer.Name, Author: c.Committer.Name,
Hash: c.Hash.String(), Hash: c.Hash.String(),

View File

@@ -69,7 +69,7 @@ func (g *Client) GetCompareURL(oldVersion, newVersion string) string {
//ValidateConfig for github //ValidateConfig for github
func (g *Client) ValidateConfig() error { func (g *Client) ValidateConfig() error {
log.Debugf("validate GitHub provider config") g.log.Debugf("validate GitHub provider config")
if g.config.Repo == "" { if g.config.Repo == "" {
return fmt.Errorf("github Repro is not set") return fmt.Errorf("github Repro is not set")
@@ -91,8 +91,6 @@ func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedC
prerelease := releaseVersion.Next.Version.Prerelease() != "" prerelease := releaseVersion.Next.Version.Prerelease() != ""
log.Debugf("Send %+v", generatedChangelog)
release, _, err := g.client.Repositories.CreateRelease(g.context, g.config.User, g.config.Repo, &github.RepositoryRelease{ release, _, err := g.client.Repositories.CreateRelease(g.context, g.config.User, g.config.Repo, &github.RepositoryRelease{
TagName: &tag, TagName: &tag,
TargetCommitish: &releaseVersion.Branch, TargetCommitish: &releaseVersion.Branch,
@@ -103,14 +101,14 @@ func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedC
}) })
if err != nil { if err != nil {
if strings.Contains(err.Error(), "already_exists") { if strings.Contains(err.Error(), "already_exists") {
log.Infof("A release with tag %s already exits, will not perform a release or update", tag) g.log.Infof("A release with tag %s already exits, will not perform a release or update", tag)
return nil return nil
} }
return fmt.Errorf("could not create release: %s", err.Error()) return fmt.Errorf("could not create release: %s", err.Error())
} }
g.release = release g.release = release
log.Debugf("Release repsone: %+v", *release) g.log.Debugf("Release repsone: %+v", *release)
log.Infof("Crated release") g.log.Infof("Crated release")
return nil return nil
} }

View File

@@ -123,7 +123,7 @@ func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedC
return err return err
} }
log.Infof("Crated release") g.log.Infof("Crated release")
return nil return nil
} }
@@ -151,7 +151,7 @@ func (g *Client) UploadAssets(repoDir string, assets []config.Asset) error {
downloadURL := fmt.Sprintf("%s/%s%s", g.baseURL, g.config.Repo, result.URL) downloadURL := fmt.Sprintf("%s/%s%s", g.baseURL, g.config.Repo, result.URL)
log.Infof("Uploaded file %s to gitlab can be downloaded under %s", file.Name(), downloadURL) g.log.Infof("Uploaded file %s to gitlab can be downloaded under %s", file.Name(), downloadURL)
path := fmt.Sprintf("%s/projects/%s/releases/%s/assets/links?name=%s&url=%s", g.apiURL, util.PathEscape(g.config.Repo), g.Release, util.PathEscape(fileInfo.Name()), downloadURL) path := fmt.Sprintf("%s/projects/%s/releases/%s/assets/links?name=%s&url=%s", g.apiURL, util.PathEscape(g.config.Repo), g.Release, util.PathEscape(fileInfo.Name()), downloadURL)
@@ -160,7 +160,7 @@ func (g *Client) UploadAssets(repoDir string, assets []config.Asset) error {
return err return err
} }
log.Infof("Link file %s with release %s", file.Name(), g.Release) g.log.Infof("Link file %s with release %s", file.Name(), g.Release)
resp, err := util.Do(g.client, req, nil) resp, err := util.Do(g.client, req, nil)
if err != nil { if err != nil {
@@ -171,7 +171,7 @@ func (g *Client) UploadAssets(repoDir string, assets []config.Asset) error {
return err return err
} }
log.Infof("Link file with release %s is done", g.Release) g.log.Infof("Link file with release %s is done", g.Release)
} }
return nil return nil
} }

View File

@@ -6,16 +6,18 @@ import (
//ReleaseVersion struct //ReleaseVersion struct
type ReleaseVersion struct { type ReleaseVersion struct {
Last ReleaseVersionEntry Last ReleaseVersionEntry `yaml:"last"`
Next ReleaseVersionEntry Next ReleaseVersionEntry `yaml:"next"`
Branch string Branch string `yaml:"branch"`
Draft bool Draft bool `yaml:"draft"`
Commits map[Release][]AnalyzedCommit `yaml:"commits"`
} }
//ReleaseVersionEntry struct //ReleaseVersionEntry struct
type ReleaseVersionEntry struct { type ReleaseVersionEntry struct {
Commit string Commit string `yaml:"commit"`
Version *semver.Version VersionString string `yaml:"version"`
Version *semver.Version `yaml:"-"`
} }
//GeneratedChangelog struct //GeneratedChangelog struct
@@ -31,3 +33,27 @@ type ChangelogTemplateConfig struct {
Hash string Hash string
Version string Version string
} }
//AnalyzedCommit struct
type AnalyzedCommit struct {
Commit Commit `yaml:"commit"`
ParsedMessage string `yaml:"parsedMessage"`
Scope Scope `yaml:"scope"`
ParsedBreakingChangeMessage string `yaml:"parsedBreakingChangeMessage"`
Tag string `yaml:"tag"`
TagString string `yaml:"tagString"`
Print bool `yaml:"print"`
}
//Scope of the commit, like feat, fix,..
type Scope string
//Release types, like major
type Release string
// Commit struct
type Commit struct {
Message string `yaml:"message"`
Author string `yaml:"author"`
Hash string `yaml:"hash"`
}

View File

@@ -62,22 +62,22 @@ func (s *SemanticRelease) GetCIProvider() (*ci.ProviderConfig, error) {
} }
// GetNextVersion from .version or calculate new from commits // GetNextVersion from .version or calculate new from commits
func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool) (*shared.ReleaseVersion, map[analyzer.Release][]analyzer.AnalyzedCommit, error) { func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool) (*shared.ReleaseVersion, error) {
log.Debugf("Ignore .version file if exits, %t", force) log.Debugf("Ignore .version file if exits, %t", force)
if !force { if !force {
releaseVersion, err := cache.Read(s.repository) releaseVersion, err := cache.Read(s.repository)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
if releaseVersion.Next.Commit == provider.Commit && releaseVersion != nil { if releaseVersion.Next.Commit == provider.Commit && releaseVersion != nil {
return releaseVersion, nil, nil return releaseVersion, nil
} }
} }
lastVersion, lastVersionHash, err := s.gitutil.GetLastVersion() lastVersion, lastVersionHash, err := s.gitutil.GetLastVersion()
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
firstRelease := false firstRelease := false
@@ -90,7 +90,7 @@ func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool
commits, err := s.gitutil.GetCommits(lastVersionHash) commits, err := s.gitutil.GetCommits(lastVersionHash)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
log.Debugf("Found %d commits till last release", len(commits)) log.Debugf("Found %d commits till last release", len(commits))
@@ -116,16 +116,17 @@ func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool
Commit: lastVersionHash, Commit: lastVersionHash,
Version: lastVersion, Version: lastVersion,
}, },
Branch: provider.Branch, Branch: provider.Branch,
Draft: isDraft, Draft: isDraft,
Commits: analyzedCommits,
} }
log.Infof("New version %s -> %s", lastVersion.String(), newVersion.String()) log.Infof("New version %s -> %s", lastVersion.String(), newVersion.String())
err = cache.Write(s.repository, releaseVersion) err = cache.Write(s.repository, releaseVersion)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
return &releaseVersion, analyzedCommits, err return &releaseVersion, err
} }
//SetVersion for git repository //SetVersion for git repository
@@ -158,14 +159,14 @@ func (s *SemanticRelease) SetVersion(provider *ci.ProviderConfig, version string
} }
// GetChangelog from last version till now // GetChangelog from last version till now
func (s *SemanticRelease) GetChangelog(analyzedCommits map[analyzer.Release][]analyzer.AnalyzedCommit, releaseVersion *shared.ReleaseVersion) (*shared.GeneratedChangelog, error) { func (s *SemanticRelease) GetChangelog(releaseVersion *shared.ReleaseVersion) (*shared.GeneratedChangelog, error) {
c := changelog.New(s.config, s.analyzer.GetRules(), time.Now()) c := changelog.New(s.config, s.analyzer.GetRules(), time.Now())
return c.GenerateChanglog(shared.ChangelogTemplateConfig{ return c.GenerateChanglog(shared.ChangelogTemplateConfig{
Version: releaseVersion.Next.Version.String(), Version: releaseVersion.Next.Version.String(),
Hash: releaseVersion.Last.Commit, Hash: releaseVersion.Last.Commit,
CommitURL: s.releaser.GetCommitURL(), CommitURL: s.releaser.GetCommitURL(),
CompareURL: s.releaser.GetCompareURL(releaseVersion.Last.Version.String(), releaseVersion.Next.Version.String()), CompareURL: s.releaser.GetCompareURL(releaseVersion.Last.Version.String(), releaseVersion.Next.Version.String()),
}, analyzedCommits) }, releaseVersion.Commits)
} }
@@ -187,7 +188,7 @@ func (s *SemanticRelease) Release(provider *ci.ProviderConfig, force bool) error
return nil return nil
} }
releaseVersion, analyzedCommits, err := s.GetNextVersion(provider, force) releaseVersion, err := s.GetNextVersion(provider, force)
if err != nil { if err != nil {
log.Debugf("Could not get next version") log.Debugf("Could not get next version")
return err return err
@@ -198,7 +199,7 @@ func (s *SemanticRelease) Release(provider *ci.ProviderConfig, force bool) error
return nil return nil
} }
generatedChanglog, err := s.GetChangelog(analyzedCommits, releaseVersion) generatedChanglog, err := s.GetChangelog(releaseVersion)
if err != nil { if err != nil {
log.Debugf("Could not get changelog") log.Debugf("Could not get changelog")
return err return err