mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-22 08:20:39 +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)
|
date, _ = time.Parse("2006-01-02", commits[0].Date)
|
||||||
}
|
}
|
||||||
|
|
||||||
releasenote := rnProcessor.Create(nil, date, commits)
|
output, err := outputFormatter.FormatReleaseNote(rnProcessor.Create(nil, date, commits))
|
||||||
fmt.Println(outputFormatter.FormatReleaseNote(releasenote))
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not format release notes, message: %v", err)
|
||||||
|
}
|
||||||
|
fmt.Println(output)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,7 +176,11 @@ func releaseNotesHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor,
|
|||||||
}
|
}
|
||||||
|
|
||||||
releasenote := rnProcessor.Create(&rnVersion, date, commits)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -442,7 +449,11 @@ func changelogHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor, rnP
|
|||||||
releaseNotes = append(releaseNotes, rnProcessor.Create(¤tVer, tag.Date, commits))
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,8 @@ const (
|
|||||||
|
|
||||||
// OutputFormatter output formatter interface.
|
// OutputFormatter output formatter interface.
|
||||||
type OutputFormatter interface {
|
type OutputFormatter interface {
|
||||||
FormatReleaseNote(releasenote ReleaseNote) string
|
FormatReleaseNote(releasenote ReleaseNote) (string, error)
|
||||||
FormatChangelog(releasenotes []ReleaseNote) string
|
FormatChangelog(releasenotes []ReleaseNote) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OutputFormatterImpl formater for release note and changelog.
|
// OutputFormatterImpl formater for release note and changelog.
|
||||||
@ -72,22 +72,26 @@ func NewOutputFormatter() *OutputFormatterImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FormatReleaseNote format a release note.
|
// FormatReleaseNote format a release note.
|
||||||
func (p OutputFormatterImpl) FormatReleaseNote(releasenote ReleaseNote) string {
|
func (p OutputFormatterImpl) FormatReleaseNote(releasenote ReleaseNote) (string, error) {
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
p.releasenoteTemplate.Execute(&b, releaseNoteVariables(releasenote))
|
if err := p.releasenoteTemplate.Execute(&b, releaseNoteVariables(releasenote)); err != nil {
|
||||||
return b.String()
|
return "", err
|
||||||
|
}
|
||||||
|
return b.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FormatChangelog format a changelog.
|
// FormatChangelog format a changelog.
|
||||||
func (p OutputFormatterImpl) FormatChangelog(releasenotes []ReleaseNote) string {
|
func (p OutputFormatterImpl) FormatChangelog(releasenotes []ReleaseNote) (string, error) {
|
||||||
templateVars := make([]releaseNoteTemplateVariables, len(releasenotes))
|
templateVars := make([]releaseNoteTemplateVariables, len(releasenotes))
|
||||||
for i, v := range releasenotes {
|
for i, v := range releasenotes {
|
||||||
templateVars[i] = releaseNoteVariables(v)
|
templateVars[i] = releaseNoteVariables(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
p.changelogTemplate.Execute(&b, templateVars)
|
if err := p.changelogTemplate.Execute(&b, templateVars); err != nil {
|
||||||
return b.String()
|
return "", err
|
||||||
|
}
|
||||||
|
return b.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func releaseNoteVariables(releasenote ReleaseNote) releaseNoteTemplateVariables {
|
func releaseNoteVariables(releasenote ReleaseNote) releaseNoteTemplateVariables {
|
||||||
|
@ -42,17 +42,23 @@ func TestOutputFormatterImpl_FormatReleaseNote(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
input ReleaseNote
|
input ReleaseNote
|
||||||
want string
|
want string
|
||||||
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{"with date", emptyReleaseNote("1.0.0", date.Truncate(time.Minute)), dateChangelog},
|
{"with date", emptyReleaseNote("1.0.0", date.Truncate(time.Minute)), dateChangelog, false},
|
||||||
{"without date", emptyReleaseNote("1.0.0", time.Time{}.Truncate(time.Minute)), emptyDateChangelog},
|
{"without date", emptyReleaseNote("1.0.0", time.Time{}.Truncate(time.Minute)), emptyDateChangelog, false},
|
||||||
{"without version", emptyReleaseNote("", date.Truncate(time.Minute)), emptyVersionChangelog},
|
{"without version", emptyReleaseNote("", date.Truncate(time.Minute)), emptyVersionChangelog, false},
|
||||||
{"full changelog", fullReleaseNote("1.0.0", date.Truncate(time.Minute)), fullChangeLog},
|
{"full changelog", fullReleaseNote("1.0.0", date.Truncate(time.Minute)), fullChangeLog, false},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
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)
|
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