0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-09-19 13:52:45 +02: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"
"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"`

View File

@ -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"
)

View File

@ -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 (

View File

@ -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()
}

View File

@ -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

View File

@ -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()

View File

@ -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)

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
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

View File

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

View File

@ -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