mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-25 07:30:38 +00:00
Merge pull request #4 from bvieira/ignore-missing-date
Feature: tags without date
This commit is contained in:
commit
c3a35e4a56
@ -40,7 +40,7 @@ const (
|
|||||||
{{- end}}
|
{{- end}}
|
||||||
{{- end}}`
|
{{- end}}`
|
||||||
|
|
||||||
rnTemplate = `## v{{.Version}} ({{.Date}})
|
rnTemplate = `## v{{.Version}}{{if .Date}} ({{.Date}}){{end}}
|
||||||
{{- template "rnSection" .Sections.feat}}
|
{{- template "rnSection" .Sections.feat}}
|
||||||
{{- template "rnSection" .Sections.fix}}
|
{{- template "rnSection" .Sections.fix}}
|
||||||
{{- template "rnSectionBreakingChanges" .BreakingChanges}}
|
{{- template "rnSectionBreakingChanges" .BreakingChanges}}
|
||||||
@ -89,9 +89,13 @@ func (p OutputFormatterImpl) FormatChangelog(releasenotes []ReleaseNote) string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func releaseNoteVariables(releasenote ReleaseNote) releaseNoteTemplateVariables {
|
func releaseNoteVariables(releasenote ReleaseNote) releaseNoteTemplateVariables {
|
||||||
|
var date = ""
|
||||||
|
if !releasenote.Date.IsZero() {
|
||||||
|
date = releasenote.Date.Format("2006-01-02")
|
||||||
|
}
|
||||||
return releaseNoteTemplateVariables{
|
return releaseNoteTemplateVariables{
|
||||||
Version: fmt.Sprintf("%d.%d.%d", releasenote.Version.Major(), releasenote.Version.Minor(), releasenote.Version.Patch()),
|
Version: fmt.Sprintf("%d.%d.%d", releasenote.Version.Major(), releasenote.Version.Minor(), releasenote.Version.Patch()),
|
||||||
Date: releasenote.Date.Format("2006-01-02"),
|
Date: date,
|
||||||
Sections: releasenote.Sections,
|
Sections: releasenote.Sections,
|
||||||
BreakingChanges: releasenote.BreakingChanges,
|
BreakingChanges: releasenote.BreakingChanges,
|
||||||
}
|
}
|
||||||
|
40
sv/formatter_test.go
Normal file
40
sv/formatter_test.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package sv
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/Masterminds/semver"
|
||||||
|
)
|
||||||
|
|
||||||
|
var dateChangelog = `## v1.0.0 (2020-05-01)
|
||||||
|
`
|
||||||
|
var emptyDateChangelog = `## v1.0.0
|
||||||
|
`
|
||||||
|
|
||||||
|
func TestOutputFormatterImpl_FormatReleaseNote(t *testing.T) {
|
||||||
|
date, _ := time.Parse("2006-01-02", "2020-05-01")
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
input ReleaseNote
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{"", emptyReleaseNote("1.0.0", date.Truncate(time.Minute)), dateChangelog},
|
||||||
|
{"", emptyReleaseNote("1.0.0", time.Time{}.Truncate(time.Minute)), emptyDateChangelog},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := NewOutputFormatter().FormatReleaseNote(tt.input); got != tt.want {
|
||||||
|
t.Errorf("OutputFormatterImpl.FormatReleaseNote() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func emptyReleaseNote(version string, date time.Time) ReleaseNote {
|
||||||
|
return ReleaseNote{
|
||||||
|
Version: *semver.MustParse(version),
|
||||||
|
Date: date,
|
||||||
|
}
|
||||||
|
}
|
@ -121,10 +121,7 @@ func parseTagsOutput(input string) ([]GitTag, error) {
|
|||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
if line := strings.TrimSpace(scanner.Text()); line != "" {
|
if line := strings.TrimSpace(scanner.Text()); line != "" {
|
||||||
values := strings.Split(line, "#")
|
values := strings.Split(line, "#")
|
||||||
date, err := time.Parse("2006-01-02 15:04:05 -0700", values[0])
|
date, _ := time.Parse("2006-01-02 15:04:05 -0700", values[0]) // ignore invalid dates
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to parse tag data, message: %v", err)
|
|
||||||
}
|
|
||||||
result = append(result, GitTag{Name: values[1], Date: date})
|
result = append(result, GitTag{Name: values[1], Date: date})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
39
sv/git_test.go
Normal file
39
sv/git_test.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package sv
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_parseTagsOutput(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
input string
|
||||||
|
want []GitTag
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{"with date", "2020-05-01 18:00:00 -0300#1.0.0", []GitTag{GitTag{Name: "1.0.0", Date: date("2020-05-01 18:00:00 -0300")}}, false},
|
||||||
|
{"without date", "#1.0.0", []GitTag{GitTag{Name: "1.0.0", Date: time.Time{}}}, false},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got, err := parseTagsOutput(tt.input)
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("parseTagsOutput() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("parseTagsOutput() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func date(input string) time.Time {
|
||||||
|
t, err := time.Parse("2006-01-02 15:04:05 -0700", input)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return t
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user