You've already forked go-semantic-release
style(lint): fix lint issues
This commit is contained in:
11
.golangci.yml
Normal file
11
.golangci.yml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
run:
|
||||||
|
tests: true
|
||||||
|
|
||||||
|
linters-settings:
|
||||||
|
golint:
|
||||||
|
min-confidence: 0
|
||||||
|
issues:
|
||||||
|
exclude-use-default: false
|
||||||
|
linters:
|
||||||
|
enable:
|
||||||
|
- golint
|
||||||
@@ -20,7 +20,7 @@ before_script:
|
|||||||
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.16.0
|
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.16.0
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- golangci-lint run
|
- golangci-lint run --golint.min-confidence 0 --exclude-use-default=no
|
||||||
- go test -v ./...
|
- go test -v ./...
|
||||||
- go build -o build/go-semantic-release ./cmd/go-semantic-release/
|
- go build -o build/go-semantic-release ./cmd/go-semantic-release/
|
||||||
- GOOS=windows GOARCH=386 go build -o build/go-semantic-release.exe ./cmd/go-semantic-release/
|
- GOOS=windows GOARCH=386 go build -o build/go-semantic-release.exe ./cmd/go-semantic-release/
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// Package main as start point for go build
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// Package analyzer provides different commit analyzer
|
||||||
package analyzer
|
package analyzer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -5,20 +6,23 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//Analyzer struct
|
||||||
type Analyzer struct {
|
type Analyzer struct {
|
||||||
CommitFormat string
|
CommitFormat string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Rules for commits
|
||||||
type Rules struct {
|
type Rules struct {
|
||||||
Tag string
|
Tag string
|
||||||
Release string
|
Release string
|
||||||
}
|
}
|
||||||
|
|
||||||
type AnalyzeCommit interface {
|
type analyzeCommit interface {
|
||||||
Analyze(commit gitutil.Commit, tag string) (AnalyzedCommit, bool)
|
analyze(commit gitutil.Commit, tag string) (AnalyzedCommit, bool)
|
||||||
GetRules() []Rules
|
getRules() []Rules
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//AnalyzedCommit struct
|
||||||
type AnalyzedCommit struct {
|
type AnalyzedCommit struct {
|
||||||
Commit gitutil.Commit
|
Commit gitutil.Commit
|
||||||
ParsedMessage string
|
ParsedMessage string
|
||||||
@@ -26,6 +30,7 @@ type AnalyzedCommit struct {
|
|||||||
ParsedBreakingChangeMessage string
|
ParsedBreakingChangeMessage string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//New Analyzer struct for given commit format
|
||||||
func New(format string) *Analyzer {
|
func New(format string) *Analyzer {
|
||||||
return &Analyzer{
|
return &Analyzer{
|
||||||
CommitFormat: format,
|
CommitFormat: format,
|
||||||
@@ -33,13 +38,14 @@ func New(format string) *Analyzer {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Analyze commits and return commits splitted by major,minor,patch
|
||||||
func (a *Analyzer) Analyze(commits []gitutil.Commit) map[string][]AnalyzedCommit {
|
func (a *Analyzer) Analyze(commits []gitutil.Commit) map[string][]AnalyzedCommit {
|
||||||
|
|
||||||
var commitAnalayzer AnalyzeCommit
|
var commitAnalayzer analyzeCommit
|
||||||
switch a.CommitFormat {
|
switch a.CommitFormat {
|
||||||
case "angular":
|
case "angular":
|
||||||
log.Infof("analyze angular format")
|
log.Infof("analyze angular format")
|
||||||
commitAnalayzer = NewAngular()
|
commitAnalayzer = newAngular()
|
||||||
}
|
}
|
||||||
|
|
||||||
analyzedCommits := make(map[string][]AnalyzedCommit)
|
analyzedCommits := make(map[string][]AnalyzedCommit)
|
||||||
@@ -48,8 +54,8 @@ func (a *Analyzer) Analyze(commits []gitutil.Commit) map[string][]AnalyzedCommit
|
|||||||
analyzedCommits["patch"] = make([]AnalyzedCommit, 0)
|
analyzedCommits["patch"] = make([]AnalyzedCommit, 0)
|
||||||
|
|
||||||
for _, commit := range commits {
|
for _, commit := range commits {
|
||||||
for _, rule := range commitAnalayzer.GetRules() {
|
for _, rule := range commitAnalayzer.getRules() {
|
||||||
analyzedCommit, hasBreakingChange := commitAnalayzer.Analyze(commit, rule.Tag)
|
analyzedCommit, hasBreakingChange := commitAnalayzer.analyze(commit, rule.Tag)
|
||||||
if hasBreakingChange {
|
if hasBreakingChange {
|
||||||
analyzedCommits["major"] = append(analyzedCommits["major"], analyzedCommit)
|
analyzedCommits["major"] = append(analyzedCommits["major"], analyzedCommit)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// Package analyzer provides different commit analyzer
|
||||||
package analyzer
|
package analyzer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -7,13 +8,13 @@ import (
|
|||||||
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Angular struct {
|
type angular struct {
|
||||||
rules []Rules
|
rules []Rules
|
||||||
regex string
|
regex string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAngular() *Angular {
|
func newAngular() *angular {
|
||||||
return &Angular{
|
return &angular{
|
||||||
regex: `(TAG)(?:\((.*)\))?: (.*)`,
|
regex: `(TAG)(?:\((.*)\))?: (.*)`,
|
||||||
rules: []Rules{
|
rules: []Rules{
|
||||||
{
|
{
|
||||||
@@ -31,11 +32,11 @@ func NewAngular() *Angular {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Angular) GetRules() []Rules {
|
func (a *angular) getRules() []Rules {
|
||||||
return a.rules
|
return a.rules
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Angular) Analyze(commit gitutil.Commit, tag string) (AnalyzedCommit, bool) {
|
func (a *angular) analyze(commit gitutil.Commit, tag string) (AnalyzedCommit, bool) {
|
||||||
|
|
||||||
analyzed := AnalyzedCommit{
|
analyzed := AnalyzedCommit{
|
||||||
Commit: commit,
|
Commit: commit,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// Package gitutil provides helper methods for git
|
||||||
package gitutil
|
package gitutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -10,29 +11,33 @@ import (
|
|||||||
"gopkg.in/src-d/go-git.v4/plumbing/object"
|
"gopkg.in/src-d/go-git.v4/plumbing/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Commit struct
|
||||||
type Commit struct {
|
type Commit struct {
|
||||||
Message string
|
Message string
|
||||||
Author string
|
Author string
|
||||||
Hash string
|
Hash string
|
||||||
}
|
}
|
||||||
|
|
||||||
type GitUtils struct {
|
// GitUtil struct
|
||||||
|
type GitUtil struct {
|
||||||
Repository *git.Repository
|
Repository *git.Repository
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(folder string) (*GitUtils, error) {
|
// New GitUtil struct and open git repository
|
||||||
|
func New(folder string) (*GitUtil, error) {
|
||||||
r, err := git.PlainOpen(folder)
|
r, err := git.PlainOpen(folder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
utils := &GitUtils{
|
utils := &GitUtil{
|
||||||
Repository: r,
|
Repository: r,
|
||||||
}
|
}
|
||||||
return utils, nil
|
return utils, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GitUtils) GetHash() (string, error) {
|
// GetHash from git HEAD
|
||||||
|
func (g *GitUtil) GetHash() (string, error) {
|
||||||
ref, err := g.Repository.Head()
|
ref, err := g.Repository.Head()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -40,20 +45,22 @@ func (g *GitUtils) GetHash() (string, error) {
|
|||||||
return ref.Hash().String(), nil
|
return ref.Hash().String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GitUtils) GetBranch() (string, error) {
|
// GetBranch from git HEAD
|
||||||
|
func (g *GitUtil) GetBranch() (string, error) {
|
||||||
ref, err := g.Repository.Head()
|
ref, err := g.Repository.Head()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ref.Name().IsBranch() {
|
if !ref.Name().IsBranch() {
|
||||||
return "", fmt.Errorf("No branch found, found %s, please checkout a branch (git checkout <BRANCH>)", ref.Name().String())
|
return "", fmt.Errorf("no branch found, found %s, please checkout a branch (git checkout <BRANCH>)", ref.Name().String())
|
||||||
}
|
}
|
||||||
|
|
||||||
return ref.Name().Short(), nil
|
return ref.Name().Short(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GitUtils) GetLastVersion() (*semver.Version, string, error) {
|
// GetLastVersion from git tags
|
||||||
|
func (g *GitUtil) GetLastVersion() (*semver.Version, string, error) {
|
||||||
|
|
||||||
log.Debugf("GetLastVersion")
|
log.Debugf("GetLastVersion")
|
||||||
|
|
||||||
@@ -103,7 +110,8 @@ func (g *GitUtils) GetLastVersion() (*semver.Version, string, error) {
|
|||||||
return tags[0], tagObject.Target.String(), nil
|
return tags[0], tagObject.Target.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GitUtils) GetCommits(lastTagHash string) ([]Commit, error) {
|
// GetCommits from git hash to HEAD
|
||||||
|
func (g *GitUtil) GetCommits(lastTagHash string) ([]Commit, error) {
|
||||||
|
|
||||||
log.Printf("Read head")
|
log.Printf("Read head")
|
||||||
ref, err := g.Repository.Head()
|
ref, err := g.Repository.Head()
|
||||||
@@ -136,5 +144,5 @@ func (g *GitUtils) GetCommits(lastTagHash string) ([]Commit, error) {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
return commits, nil
|
return commits, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// Package storage helper for saving/reading version file
|
||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// Package semanticrelease provides public methods to include in own code
|
||||||
package semanticrelease
|
package semanticrelease
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -10,7 +11,7 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetNextVersion from .version or calculate new
|
// GetNextVersion from .version or calculate new from commits
|
||||||
func GetNextVersion(repro string) error {
|
func GetNextVersion(repro string) error {
|
||||||
util, err := gitutil.New(repro)
|
util, err := gitutil.New(repro)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -38,8 +39,11 @@ func GetNextVersion(repro string) error {
|
|||||||
|
|
||||||
if lastVersion == nil {
|
if lastVersion == nil {
|
||||||
defaultVersion, _ := semver.NewVersion("1.0.0")
|
defaultVersion, _ := semver.NewVersion("1.0.0")
|
||||||
SetVersion(defaultVersion.String(), repro)
|
err := SetVersion(defaultVersion.String(), repro)
|
||||||
fmt.Printf(defaultVersion.String())
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Printf("%s", defaultVersion.String())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,12 +68,16 @@ func GetNextVersion(repro string) error {
|
|||||||
newVersion = lastVersion.IncPatch()
|
newVersion = lastVersion.IncPatch()
|
||||||
}
|
}
|
||||||
|
|
||||||
SetVersion(newVersion.String(), repro)
|
err = SetVersion(newVersion.String(), repro)
|
||||||
fmt.Printf(newVersion.String())
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Printf("%s", newVersion.String())
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SetVersion for git repository
|
||||||
func SetVersion(version string, repro string) error {
|
func SetVersion(version string, repro string) error {
|
||||||
|
|
||||||
util, err := gitutil.New(repro)
|
util, err := gitutil.New(repro)
|
||||||
@@ -109,6 +117,3 @@ func SetVersion(version string, repro string) error {
|
|||||||
|
|
||||||
return storage.Write(newVersionContent)
|
return storage.Write(newVersionContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Release() {
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user