0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-10 02:10:38 +00:00

chore: run lint autofix

This commit is contained in:
Beatriz Vieira 2021-07-31 16:03:58 -03:00
parent c037311d1a
commit b83c6e335d
10 changed files with 41 additions and 37 deletions

View File

@ -10,13 +10,12 @@ import (
"strings" "strings"
"github.com/bvieira/sv4git/sv" "github.com/bvieira/sv4git/sv"
"github.com/imdario/mergo" "github.com/imdario/mergo"
"github.com/kelseyhightower/envconfig" "github.com/kelseyhightower/envconfig"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
// EnvConfig env vars for cli configuration // EnvConfig env vars for cli configuration.
type EnvConfig struct { type EnvConfig struct {
Home string `envconfig:"SV4GIT_HOME" default:""` Home string `envconfig:"SV4GIT_HOME" default:""`
} }
@ -30,7 +29,7 @@ func loadEnvConfig() EnvConfig {
return c return c
} }
// Config cli yaml config // Config cli yaml config.
type Config struct { type Config struct {
Version string `yaml:"version"` Version string `yaml:"version"`
Versioning sv.VersioningConfig `yaml:"versioning"` Versioning sv.VersioningConfig `yaml:"versioning"`

View File

@ -10,9 +10,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/bvieira/sv4git/sv"
"github.com/Masterminds/semver/v3" "github.com/Masterminds/semver/v3"
"github.com/bvieira/sv4git/sv"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )

View File

@ -6,11 +6,10 @@ import (
"path/filepath" "path/filepath"
"github.com/bvieira/sv4git/sv" "github.com/bvieira/sv4git/sv"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
// Version for git-sv // Version for git-sv.
var Version = "" var Version = ""
const ( const (

View File

@ -78,7 +78,7 @@ func (p OutputFormatterImpl) FormatReleaseNote(releasenote ReleaseNote) string {
return b.String() return b.String()
} }
// FormatChangelog format a changelog // FormatChangelog format a changelog.
func (p OutputFormatterImpl) FormatChangelog(releasenotes []ReleaseNote) string { func (p OutputFormatterImpl) FormatChangelog(releasenotes []ReleaseNote) string {
var templateVars []releaseNoteTemplateVariables var templateVars []releaseNoteTemplateVariables
for _, v := range releasenotes { for _, v := range releasenotes {
@ -91,12 +91,12 @@ func (p OutputFormatterImpl) FormatChangelog(releasenotes []ReleaseNote) string
} }
func releaseNoteVariables(releasenote ReleaseNote) releaseNoteTemplateVariables { func releaseNoteVariables(releasenote ReleaseNote) releaseNoteTemplateVariables {
var date = "" date := ""
if !releasenote.Date.IsZero() { if !releasenote.Date.IsZero() {
date = releasenote.Date.Format("2006-01-02") date = releasenote.Date.Format("2006-01-02")
} }
var version = "" version := ""
if releasenote.Version != nil { if releasenote.Version != nil {
version = releasenote.Version.String() version = releasenote.Version.String()
} }

View File

@ -9,10 +9,13 @@ import (
var dateChangelog = `## v1.0.0 (2020-05-01) var dateChangelog = `## v1.0.0 (2020-05-01)
` `
var emptyDateChangelog = `## v1.0.0 var emptyDateChangelog = `## v1.0.0
` `
var emptyVersionChangelog = `## 2020-05-01 var emptyVersionChangelog = `## 2020-05-01
` `
var fullChangeLog = `## v1.0.0 (2020-05-01) var fullChangeLog = `## v1.0.0 (2020-05-01)
### Features ### Features

View File

@ -18,7 +18,7 @@ const (
endLine = "~~" endLine = "~~"
) )
// Git commands // Git commands.
type Git interface { type Git interface {
LastTag() string LastTag() string
Log(lr LogRange) ([]GitCommitLog, error) Log(lr LogRange) ([]GitCommitLog, error)
@ -29,48 +29,48 @@ type Git interface {
IsDetached() (bool, error) IsDetached() (bool, error)
} }
// GitCommitLog description of a single commit log // GitCommitLog description of a single commit log.
type GitCommitLog struct { type GitCommitLog struct {
Date string `json:"date,omitempty"` Date string `json:"date,omitempty"`
Hash string `json:"hash,omitempty"` Hash string `json:"hash,omitempty"`
Message CommitMessage `json:"message,omitempty"` Message CommitMessage `json:"message,omitempty"`
} }
// GitTag git tag info // GitTag git tag info.
type GitTag struct { type GitTag struct {
Name string Name string
Date time.Time Date time.Time
} }
// LogRangeType type of log range // LogRangeType type of log range.
type LogRangeType string type LogRangeType string
// constants for log range type // constants for log range type.
const ( const (
TagRange LogRangeType = "tag" TagRange LogRangeType = "tag"
DateRange = "date" DateRange = "date"
HashRange = "hash" HashRange = "hash"
) )
// LogRange git log range // LogRange git log range.
type LogRange struct { type LogRange struct {
rangeType LogRangeType rangeType LogRangeType
start string start string
end string end string
} }
// NewLogRange LogRange constructor // NewLogRange LogRange constructor.
func NewLogRange(t LogRangeType, start, end string) LogRange { func NewLogRange(t LogRangeType, start, end string) LogRange {
return LogRange{rangeType: t, start: start, end: end} return LogRange{rangeType: t, start: start, end: end}
} }
// GitImpl git command implementation // GitImpl git command implementation.
type GitImpl struct { type GitImpl struct {
messageProcessor MessageProcessor messageProcessor MessageProcessor
tagCfg TagConfig tagCfg TagConfig
} }
// NewGit constructor // NewGit constructor.
func NewGit(messageProcessor MessageProcessor, cfg TagConfig) *GitImpl { func NewGit(messageProcessor MessageProcessor, cfg TagConfig) *GitImpl {
return &GitImpl{ return &GitImpl{
messageProcessor: messageProcessor, messageProcessor: messageProcessor,
@ -78,7 +78,7 @@ func NewGit(messageProcessor MessageProcessor, cfg TagConfig) *GitImpl {
} }
} }
// LastTag get last tag, if no tag found, return empty // LastTag get last tag, if no tag found, return empty.
func (GitImpl) LastTag() string { func (GitImpl) LastTag() string {
cmd := exec.Command("git", "for-each-ref", "refs/tags", "--sort", "-creatordate", "--format", "%(refname:short)", "--count", "1") cmd := exec.Command("git", "for-each-ref", "refs/tags", "--sort", "-creatordate", "--format", "%(refname:short)", "--count", "1")
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
@ -88,7 +88,7 @@ func (GitImpl) LastTag() string {
return strings.TrimSpace(strings.Trim(string(out), "\n")) return strings.TrimSpace(strings.Trim(string(out), "\n"))
} }
// Log return git log // Log return git log.
func (g GitImpl) Log(lr LogRange) ([]GitCommitLog, error) { func (g GitImpl) Log(lr LogRange) ([]GitCommitLog, error) {
format := "--pretty=format:\"%ad" + logSeparator + "%h" + logSeparator + "%s" + logSeparator + "%b" + endLine + "\"" format := "--pretty=format:\"%ad" + logSeparator + "%h" + logSeparator + "%s" + logSeparator + "%b" + endLine + "\""
params := []string{"log", "--date=short", format} params := []string{"log", "--date=short", format}
@ -114,7 +114,7 @@ func (g GitImpl) Log(lr LogRange) ([]GitCommitLog, error) {
return parseLogOutput(g.messageProcessor, string(out)), nil return parseLogOutput(g.messageProcessor, string(out)), nil
} }
// Commit runs git commit // Commit runs git commit.
func (g GitImpl) Commit(header, body, footer string) error { func (g GitImpl) Commit(header, body, footer string) error {
cmd := exec.Command("git", "commit", "-m", header, "-m", "", "-m", body, "-m", "", "-m", footer) cmd := exec.Command("git", "commit", "-m", header, "-m", "", "-m", body, "-m", "", "-m", footer)
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
@ -122,7 +122,7 @@ func (g GitImpl) Commit(header, body, footer string) error {
return cmd.Run() return cmd.Run()
} }
// Tag create a git tag // Tag create a git tag.
func (g GitImpl) Tag(version semver.Version) error { func (g GitImpl) Tag(version semver.Version) error {
tag := fmt.Sprintf(g.tagCfg.Pattern, version.Major(), version.Minor(), version.Patch()) tag := fmt.Sprintf(g.tagCfg.Pattern, version.Major(), version.Minor(), version.Patch())
tagMsg := fmt.Sprintf("Version %d.%d.%d", version.Major(), version.Minor(), version.Patch()) tagMsg := fmt.Sprintf("Version %d.%d.%d", version.Major(), version.Minor(), version.Patch())
@ -136,7 +136,7 @@ func (g GitImpl) Tag(version semver.Version) error {
return pushCommand.Run() return pushCommand.Run()
} }
// Tags list repository tags // Tags list repository tags.
func (g GitImpl) Tags() ([]GitTag, error) { func (g GitImpl) Tags() ([]GitTag, error) {
cmd := exec.Command("git", "for-each-ref", "--sort", "creatordate", "--format", "%(creatordate:iso8601)#%(refname:short)", "refs/tags") cmd := exec.Command("git", "for-each-ref", "--sort", "creatordate", "--format", "%(creatordate:iso8601)#%(refname:short)", "refs/tags")
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
@ -146,7 +146,7 @@ func (g GitImpl) Tags() ([]GitTag, error) {
return parseTagsOutput(string(out)) return parseTagsOutput(string(out))
} }
// Branch get git branch // Branch get git branch.
func (GitImpl) Branch() string { func (GitImpl) Branch() string {
cmd := exec.Command("git", "symbolic-ref", "--short", "HEAD") cmd := exec.Command("git", "symbolic-ref", "--short", "HEAD")
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()

View File

@ -23,7 +23,7 @@ type CommitMessage struct {
Metadata map[string]string `json:"metadata,omitempty"` Metadata map[string]string `json:"metadata,omitempty"`
} }
// NewCommitMessage commit message constructor // NewCommitMessage commit message constructor.
func NewCommitMessage(ctype, scope, description, body, issue, breakingChanges string) CommitMessage { func NewCommitMessage(ctype, scope, description, body, issue, breakingChanges string) CommitMessage {
metadata := make(map[string]string) metadata := make(map[string]string)
if issue != "" { if issue != "" {
@ -58,7 +58,7 @@ type MessageProcessor interface {
Parse(subject, body string) CommitMessage Parse(subject, body string) CommitMessage
} }
// NewMessageProcessor MessageProcessorImpl constructor // NewMessageProcessor MessageProcessorImpl constructor.
func NewMessageProcessor(mcfg CommitMessageConfig, bcfg BranchesConfig) *MessageProcessorImpl { func NewMessageProcessor(mcfg CommitMessageConfig, bcfg BranchesConfig) *MessageProcessorImpl {
return &MessageProcessorImpl{ return &MessageProcessorImpl{
messageCfg: mcfg, messageCfg: mcfg,

View File

@ -62,7 +62,7 @@ func newBranchCfg(skipDetached bool) BranchesConfig {
} }
} }
// messages samples start // messages samples start.
var fullMessage = `fix: correct minor typos in code var fullMessage = `fix: correct minor typos in code
see the issue for details see the issue for details
@ -71,6 +71,7 @@ on typos fixed.
Reviewed-by: Z Reviewed-by: Z
Refs #133` Refs #133`
var fullMessageWithJira = `fix: correct minor typos in code var fullMessageWithJira = `fix: correct minor typos in code
see the issue for details see the issue for details
@ -80,6 +81,7 @@ on typos fixed.
Reviewed-by: Z Reviewed-by: Z
Refs #133 Refs #133
jira: JIRA-456` jira: JIRA-456`
var fullMessageRefs = `fix: correct minor typos in code var fullMessageRefs = `fix: correct minor typos in code
see the issue for details see the issue for details
@ -87,11 +89,13 @@ see the issue for details
on typos fixed. on typos fixed.
Refs #133` Refs #133`
var subjectAndBodyMessage = `fix: correct minor typos in code var subjectAndBodyMessage = `fix: correct minor typos in code
see the issue for details see the issue for details
on typos fixed.` on typos fixed.`
var subjectAndFooterMessage = `refactor!: drop support for Node 6 var subjectAndFooterMessage = `refactor!: drop support for Node 6
BREAKING CHANGE: refactor to use JavaScript features not available in Node 6.` BREAKING CHANGE: refactor to use JavaScript features not available in Node 6.`
@ -470,7 +474,7 @@ func Test_splitCommitMessageContent(t *testing.T) {
} }
} }
//commitType, scope, description, hasBreakingChange //commitType, scope, description, hasBreakingChange.
func Test_parseSubjectMessage(t *testing.T) { func Test_parseSubjectMessage(t *testing.T) {
tests := []struct { tests := []struct {
name string name string

View File

@ -55,7 +55,7 @@ type ReleaseNote struct {
BreakingChanges BreakingChangeSection BreakingChanges BreakingChangeSection
} }
// BreakingChangeSection breaking change section // BreakingChangeSection breaking change section.
type BreakingChangeSection struct { type BreakingChangeSection struct {
Name string Name string
Messages []string Messages []string

View File

@ -11,7 +11,7 @@ const (
major major
) )
// ToVersion parse string to semver.Version // ToVersion parse string to semver.Version.
func ToVersion(value string) (semver.Version, error) { func ToVersion(value string) (semver.Version, error) {
version := value version := value
if version == "" { if version == "" {
@ -24,12 +24,12 @@ func ToVersion(value string) (semver.Version, error) {
return *v, nil return *v, nil
} }
// SemVerCommitsProcessor interface // SemVerCommitsProcessor interface.
type SemVerCommitsProcessor interface { type SemVerCommitsProcessor interface {
NextVersion(version semver.Version, commits []GitCommitLog) (semver.Version, bool) NextVersion(version semver.Version, commits []GitCommitLog) (semver.Version, bool)
} }
// SemVerCommitsProcessorImpl process versions using commit log // SemVerCommitsProcessorImpl process versions using commit log.
type SemVerCommitsProcessorImpl struct { type SemVerCommitsProcessorImpl struct {
MajorVersionTypes map[string]struct{} MajorVersionTypes map[string]struct{}
MinorVersionTypes map[string]struct{} MinorVersionTypes map[string]struct{}
@ -38,7 +38,7 @@ type SemVerCommitsProcessorImpl struct {
IncludeUnknownTypeAsPatch bool IncludeUnknownTypeAsPatch bool
} }
// NewSemVerCommitsProcessor SemanticVersionCommitsProcessorImpl constructor // NewSemVerCommitsProcessor SemanticVersionCommitsProcessorImpl constructor.
func NewSemVerCommitsProcessor(vcfg VersioningConfig, mcfg CommitMessageConfig) *SemVerCommitsProcessorImpl { func NewSemVerCommitsProcessor(vcfg VersioningConfig, mcfg CommitMessageConfig) *SemVerCommitsProcessorImpl {
return &SemVerCommitsProcessorImpl{ return &SemVerCommitsProcessorImpl{
IncludeUnknownTypeAsPatch: !vcfg.IgnoreUnknown, IncludeUnknownTypeAsPatch: !vcfg.IgnoreUnknown,
@ -49,9 +49,9 @@ func NewSemVerCommitsProcessor(vcfg VersioningConfig, mcfg CommitMessageConfig)
} }
} }
// NextVersion calculates next version based on commit log // NextVersion calculates next version based on commit log.
func (p SemVerCommitsProcessorImpl) NextVersion(version semver.Version, commits []GitCommitLog) (semver.Version, bool) { func (p SemVerCommitsProcessorImpl) NextVersion(version semver.Version, commits []GitCommitLog) (semver.Version, bool) {
var versionToUpdate = none versionToUpdate := none
for _, commit := range commits { for _, commit := range commits {
if v := p.versionTypeToUpdate(commit); v > versionToUpdate { if v := p.versionTypeToUpdate(commit); v > versionToUpdate {
versionToUpdate = v versionToUpdate = v