From b83c6e335d23810d25e2c87bb0fb8ad46247f3c8 Mon Sep 17 00:00:00 2001 From: Beatriz Vieira Date: Sat, 31 Jul 2021 16:03:58 -0300 Subject: [PATCH] chore: run lint autofix --- cmd/git-sv/config.go | 5 ++--- cmd/git-sv/handlers.go | 3 +-- cmd/git-sv/main.go | 3 +-- sv/formatter.go | 6 +++--- sv/formatter_test.go | 3 +++ sv/git.go | 30 +++++++++++++++--------------- sv/message.go | 6 +++--- sv/message_test.go | 8 ++++++-- sv/releasenotes.go | 2 +- sv/semver.go | 12 ++++++------ 10 files changed, 41 insertions(+), 37 deletions(-) diff --git a/cmd/git-sv/config.go b/cmd/git-sv/config.go index dfb00dc..9e34d6b 100644 --- a/cmd/git-sv/config.go +++ b/cmd/git-sv/config.go @@ -10,13 +10,12 @@ import ( "strings" "github.com/bvieira/sv4git/sv" - "github.com/imdario/mergo" "github.com/kelseyhightower/envconfig" "gopkg.in/yaml.v3" ) -// EnvConfig env vars for cli configuration +// EnvConfig env vars for cli configuration. type EnvConfig struct { Home string `envconfig:"SV4GIT_HOME" default:""` } @@ -30,7 +29,7 @@ func loadEnvConfig() EnvConfig { return c } -// Config cli yaml config +// Config cli yaml config. type Config struct { Version string `yaml:"version"` Versioning sv.VersioningConfig `yaml:"versioning"` diff --git a/cmd/git-sv/handlers.go b/cmd/git-sv/handlers.go index 64a8564..cd8c79b 100644 --- a/cmd/git-sv/handlers.go +++ b/cmd/git-sv/handlers.go @@ -10,9 +10,8 @@ import ( "strings" "time" - "github.com/bvieira/sv4git/sv" - "github.com/Masterminds/semver/v3" + "github.com/bvieira/sv4git/sv" "github.com/urfave/cli/v2" "gopkg.in/yaml.v3" ) diff --git a/cmd/git-sv/main.go b/cmd/git-sv/main.go index 12c5525..670ff92 100644 --- a/cmd/git-sv/main.go +++ b/cmd/git-sv/main.go @@ -6,11 +6,10 @@ import ( "path/filepath" "github.com/bvieira/sv4git/sv" - "github.com/urfave/cli/v2" ) -// Version for git-sv +// Version for git-sv. var Version = "" const ( diff --git a/sv/formatter.go b/sv/formatter.go index abb9316..6509e8b 100644 --- a/sv/formatter.go +++ b/sv/formatter.go @@ -78,7 +78,7 @@ func (p OutputFormatterImpl) FormatReleaseNote(releasenote ReleaseNote) string { return b.String() } -// FormatChangelog format a changelog +// FormatChangelog format a changelog. func (p OutputFormatterImpl) FormatChangelog(releasenotes []ReleaseNote) string { var templateVars []releaseNoteTemplateVariables for _, v := range releasenotes { @@ -91,12 +91,12 @@ func (p OutputFormatterImpl) FormatChangelog(releasenotes []ReleaseNote) string } func releaseNoteVariables(releasenote ReleaseNote) releaseNoteTemplateVariables { - var date = "" + date := "" if !releasenote.Date.IsZero() { date = releasenote.Date.Format("2006-01-02") } - var version = "" + version := "" if releasenote.Version != nil { version = releasenote.Version.String() } diff --git a/sv/formatter_test.go b/sv/formatter_test.go index 263e6d7..d460605 100644 --- a/sv/formatter_test.go +++ b/sv/formatter_test.go @@ -9,10 +9,13 @@ import ( var dateChangelog = `## v1.0.0 (2020-05-01) ` + var emptyDateChangelog = `## v1.0.0 ` + var emptyVersionChangelog = `## 2020-05-01 ` + var fullChangeLog = `## v1.0.0 (2020-05-01) ### Features diff --git a/sv/git.go b/sv/git.go index dde3242..7d873c9 100644 --- a/sv/git.go +++ b/sv/git.go @@ -18,7 +18,7 @@ const ( endLine = "~~" ) -// Git commands +// Git commands. type Git interface { LastTag() string Log(lr LogRange) ([]GitCommitLog, error) @@ -29,48 +29,48 @@ type Git interface { IsDetached() (bool, error) } -// GitCommitLog description of a single commit log +// GitCommitLog description of a single commit log. type GitCommitLog struct { Date string `json:"date,omitempty"` Hash string `json:"hash,omitempty"` Message CommitMessage `json:"message,omitempty"` } -// GitTag git tag info +// GitTag git tag info. type GitTag struct { Name string Date time.Time } -// LogRangeType type of log range +// LogRangeType type of log range. type LogRangeType string -// constants for log range type +// constants for log range type. const ( TagRange LogRangeType = "tag" DateRange = "date" HashRange = "hash" ) -// LogRange git log range +// LogRange git log range. type LogRange struct { rangeType LogRangeType start string end string } -// NewLogRange LogRange constructor +// NewLogRange LogRange constructor. func NewLogRange(t LogRangeType, start, end string) LogRange { return LogRange{rangeType: t, start: start, end: end} } -// GitImpl git command implementation +// GitImpl git command implementation. type GitImpl struct { messageProcessor MessageProcessor tagCfg TagConfig } -// NewGit constructor +// NewGit constructor. func NewGit(messageProcessor MessageProcessor, cfg TagConfig) *GitImpl { return &GitImpl{ 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 { cmd := exec.Command("git", "for-each-ref", "refs/tags", "--sort", "-creatordate", "--format", "%(refname:short)", "--count", "1") out, err := cmd.CombinedOutput() @@ -88,7 +88,7 @@ func (GitImpl) LastTag() string { return strings.TrimSpace(strings.Trim(string(out), "\n")) } -// Log return git log +// Log return git log. func (g GitImpl) Log(lr LogRange) ([]GitCommitLog, error) { format := "--pretty=format:\"%ad" + logSeparator + "%h" + logSeparator + "%s" + logSeparator + "%b" + endLine + "\"" 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 } -// Commit runs git commit +// Commit runs git commit. func (g GitImpl) Commit(header, body, footer string) error { cmd := exec.Command("git", "commit", "-m", header, "-m", "", "-m", body, "-m", "", "-m", footer) cmd.Stdout = os.Stdout @@ -122,7 +122,7 @@ func (g GitImpl) Commit(header, body, footer string) error { return cmd.Run() } -// Tag create a git tag +// Tag create a git tag. func (g GitImpl) Tag(version semver.Version) error { 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()) @@ -136,7 +136,7 @@ func (g GitImpl) Tag(version semver.Version) error { return pushCommand.Run() } -// Tags list repository tags +// Tags list repository tags. func (g GitImpl) Tags() ([]GitTag, error) { cmd := exec.Command("git", "for-each-ref", "--sort", "creatordate", "--format", "%(creatordate:iso8601)#%(refname:short)", "refs/tags") out, err := cmd.CombinedOutput() @@ -146,7 +146,7 @@ func (g GitImpl) Tags() ([]GitTag, error) { return parseTagsOutput(string(out)) } -// Branch get git branch +// Branch get git branch. func (GitImpl) Branch() string { cmd := exec.Command("git", "symbolic-ref", "--short", "HEAD") out, err := cmd.CombinedOutput() diff --git a/sv/message.go b/sv/message.go index cc5e354..fd08ef1 100644 --- a/sv/message.go +++ b/sv/message.go @@ -23,7 +23,7 @@ type CommitMessage struct { 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 { metadata := make(map[string]string) if issue != "" { @@ -58,7 +58,7 @@ type MessageProcessor interface { Parse(subject, body string) CommitMessage } -// NewMessageProcessor MessageProcessorImpl constructor +// NewMessageProcessor MessageProcessorImpl constructor. func NewMessageProcessor(mcfg CommitMessageConfig, bcfg BranchesConfig) *MessageProcessorImpl { return &MessageProcessorImpl{ messageCfg: mcfg, @@ -125,7 +125,7 @@ func (p MessageProcessorImpl) ValidateDescription(description string) error { // Enhance add metadata on commit message. func (p MessageProcessorImpl) Enhance(branch string, message string) (string, error) { if p.branchesCfg.DisableIssue || p.messageCfg.IssueFooterConfig().Key == "" || hasIssueID(message, p.messageCfg.IssueFooterConfig()) { - return "", nil //enhance disabled + return "", nil // enhance disabled } issue, err := p.IssueID(branch) diff --git a/sv/message_test.go b/sv/message_test.go index 4d3c43f..1992d1b 100644 --- a/sv/message_test.go +++ b/sv/message_test.go @@ -62,7 +62,7 @@ func newBranchCfg(skipDetached bool) BranchesConfig { } } -// messages samples start +// messages samples start. var fullMessage = `fix: correct minor typos in code see the issue for details @@ -71,6 +71,7 @@ on typos fixed. Reviewed-by: Z Refs #133` + var fullMessageWithJira = `fix: correct minor typos in code see the issue for details @@ -80,6 +81,7 @@ on typos fixed. Reviewed-by: Z Refs #133 jira: JIRA-456` + var fullMessageRefs = `fix: correct minor typos in code see the issue for details @@ -87,11 +89,13 @@ see the issue for details on typos fixed. Refs #133` + var subjectAndBodyMessage = `fix: correct minor typos in code see the issue for details on typos fixed.` + var subjectAndFooterMessage = `refactor!: drop support for 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) { tests := []struct { name string diff --git a/sv/releasenotes.go b/sv/releasenotes.go index e02c291..7fafeb7 100644 --- a/sv/releasenotes.go +++ b/sv/releasenotes.go @@ -55,7 +55,7 @@ type ReleaseNote struct { BreakingChanges BreakingChangeSection } -// BreakingChangeSection breaking change section +// BreakingChangeSection breaking change section. type BreakingChangeSection struct { Name string Messages []string diff --git a/sv/semver.go b/sv/semver.go index 06d76d1..b648da6 100644 --- a/sv/semver.go +++ b/sv/semver.go @@ -11,7 +11,7 @@ const ( major ) -// ToVersion parse string to semver.Version +// ToVersion parse string to semver.Version. func ToVersion(value string) (semver.Version, error) { version := value if version == "" { @@ -24,12 +24,12 @@ func ToVersion(value string) (semver.Version, error) { return *v, nil } -// SemVerCommitsProcessor interface +// SemVerCommitsProcessor interface. type SemVerCommitsProcessor interface { NextVersion(version semver.Version, commits []GitCommitLog) (semver.Version, bool) } -// SemVerCommitsProcessorImpl process versions using commit log +// SemVerCommitsProcessorImpl process versions using commit log. type SemVerCommitsProcessorImpl struct { MajorVersionTypes map[string]struct{} MinorVersionTypes map[string]struct{} @@ -38,7 +38,7 @@ type SemVerCommitsProcessorImpl struct { IncludeUnknownTypeAsPatch bool } -// NewSemVerCommitsProcessor SemanticVersionCommitsProcessorImpl constructor +// NewSemVerCommitsProcessor SemanticVersionCommitsProcessorImpl constructor. func NewSemVerCommitsProcessor(vcfg VersioningConfig, mcfg CommitMessageConfig) *SemVerCommitsProcessorImpl { return &SemVerCommitsProcessorImpl{ 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) { - var versionToUpdate = none + versionToUpdate := none for _, commit := range commits { if v := p.versionTypeToUpdate(commit); v > versionToUpdate { versionToUpdate = v