mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-09 16:00:40 +00:00
refactor: fix errcheck lint
This commit is contained in:
parent
7b3df4e245
commit
fec91a1947
@ -148,8 +148,11 @@ func commitNotesHandler(git sv.Git, rnProcessor sv.ReleaseNoteProcessor, outputF
|
||||
date, _ = time.Parse("2006-01-02", commits[0].Date)
|
||||
}
|
||||
|
||||
releasenote := rnProcessor.Create(nil, date, commits)
|
||||
fmt.Println(outputFormatter.FormatReleaseNote(releasenote))
|
||||
output, err := outputFormatter.FormatReleaseNote(rnProcessor.Create(nil, date, commits))
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not format release notes, message: %v", err)
|
||||
}
|
||||
fmt.Println(output)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -173,7 +176,11 @@ func releaseNotesHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor,
|
||||
}
|
||||
|
||||
releasenote := rnProcessor.Create(&rnVersion, date, commits)
|
||||
fmt.Println(outputFormatter.FormatReleaseNote(releasenote))
|
||||
output, err := outputFormatter.FormatReleaseNote(releasenote)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not format release notes, message: %v", err)
|
||||
}
|
||||
fmt.Println(output)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -442,7 +449,11 @@ func changelogHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor, rnP
|
||||
releaseNotes = append(releaseNotes, rnProcessor.Create(¤tVer, tag.Date, commits))
|
||||
}
|
||||
|
||||
fmt.Println(formatter.FormatChangelog(releaseNotes))
|
||||
output, err := formatter.FormatChangelog(releaseNotes)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not format changelog, message: %v", err)
|
||||
}
|
||||
fmt.Println(output)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -51,8 +51,8 @@ const (
|
||||
|
||||
// OutputFormatter output formatter interface.
|
||||
type OutputFormatter interface {
|
||||
FormatReleaseNote(releasenote ReleaseNote) string
|
||||
FormatChangelog(releasenotes []ReleaseNote) string
|
||||
FormatReleaseNote(releasenote ReleaseNote) (string, error)
|
||||
FormatChangelog(releasenotes []ReleaseNote) (string, error)
|
||||
}
|
||||
|
||||
// OutputFormatterImpl formater for release note and changelog.
|
||||
@ -72,22 +72,26 @@ func NewOutputFormatter() *OutputFormatterImpl {
|
||||
}
|
||||
|
||||
// FormatReleaseNote format a release note.
|
||||
func (p OutputFormatterImpl) FormatReleaseNote(releasenote ReleaseNote) string {
|
||||
func (p OutputFormatterImpl) FormatReleaseNote(releasenote ReleaseNote) (string, error) {
|
||||
var b bytes.Buffer
|
||||
p.releasenoteTemplate.Execute(&b, releaseNoteVariables(releasenote))
|
||||
return b.String()
|
||||
if err := p.releasenoteTemplate.Execute(&b, releaseNoteVariables(releasenote)); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return b.String(), nil
|
||||
}
|
||||
|
||||
// FormatChangelog format a changelog.
|
||||
func (p OutputFormatterImpl) FormatChangelog(releasenotes []ReleaseNote) string {
|
||||
func (p OutputFormatterImpl) FormatChangelog(releasenotes []ReleaseNote) (string, error) {
|
||||
templateVars := make([]releaseNoteTemplateVariables, len(releasenotes))
|
||||
for i, v := range releasenotes {
|
||||
templateVars[i] = releaseNoteVariables(v)
|
||||
}
|
||||
|
||||
var b bytes.Buffer
|
||||
p.changelogTemplate.Execute(&b, templateVars)
|
||||
return b.String()
|
||||
if err := p.changelogTemplate.Execute(&b, templateVars); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return b.String(), nil
|
||||
}
|
||||
|
||||
func releaseNoteVariables(releasenote ReleaseNote) releaseNoteTemplateVariables {
|
||||
|
@ -39,20 +39,26 @@ func TestOutputFormatterImpl_FormatReleaseNote(t *testing.T) {
|
||||
date, _ := time.Parse("2006-01-02", "2020-05-01")
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
input ReleaseNote
|
||||
want string
|
||||
name string
|
||||
input ReleaseNote
|
||||
want string
|
||||
wantErr bool
|
||||
}{
|
||||
{"with date", emptyReleaseNote("1.0.0", date.Truncate(time.Minute)), dateChangelog},
|
||||
{"without date", emptyReleaseNote("1.0.0", time.Time{}.Truncate(time.Minute)), emptyDateChangelog},
|
||||
{"without version", emptyReleaseNote("", date.Truncate(time.Minute)), emptyVersionChangelog},
|
||||
{"full changelog", fullReleaseNote("1.0.0", date.Truncate(time.Minute)), fullChangeLog},
|
||||
{"with date", emptyReleaseNote("1.0.0", date.Truncate(time.Minute)), dateChangelog, false},
|
||||
{"without date", emptyReleaseNote("1.0.0", time.Time{}.Truncate(time.Minute)), emptyDateChangelog, false},
|
||||
{"without version", emptyReleaseNote("", date.Truncate(time.Minute)), emptyVersionChangelog, false},
|
||||
{"full changelog", fullReleaseNote("1.0.0", date.Truncate(time.Minute)), fullChangeLog, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := NewOutputFormatter().FormatReleaseNote(tt.input); got != tt.want {
|
||||
got, err := NewOutputFormatter().FormatReleaseNote(tt.input)
|
||||
if got != tt.want {
|
||||
t.Errorf("OutputFormatterImpl.FormatReleaseNote() = %v, want %v", got, tt.want)
|
||||
}
|
||||
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("OutputFormatterImpl.FormatReleaseNote() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user