0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-28 16:40:36 +00:00

feat: support more commit-types on release notes in a fixed order

add sections for the following types: feat, fix, refactor, perf, test, build, ci, chore, docs, style

issue: #24
This commit is contained in:
Beatriz Vieira 2021-07-30 21:03:34 -03:00
parent 206f6a9105
commit e9f4c144d8
2 changed files with 41 additions and 4 deletions

View File

@ -9,6 +9,7 @@ type releaseNoteTemplateVariables struct {
Version string Version string
Date string Date string
Sections map[string]ReleaseNoteSection Sections map[string]ReleaseNoteSection
Order []string
BreakingChanges BreakingChangeSection BreakingChanges BreakingChangeSection
} }
@ -23,13 +24,13 @@ const (
rnSectionItem = "- {{if .Message.Scope}}**{{.Message.Scope}}:** {{end}}{{.Message.Description}} ({{.Hash}}){{if .Message.Metadata.issue}} ({{.Message.Metadata.issue}}){{end}}" rnSectionItem = "- {{if .Message.Scope}}**{{.Message.Scope}}:** {{end}}{{.Message.Description}} ({{.Hash}}){{if .Message.Metadata.issue}} ({{.Message.Metadata.issue}}){{end}}"
rnSection = `{{- if .}} rnSection = `{{- if .}}{{- if ne .Name ""}}
### {{.Name}} ### {{.Name}}
{{range $k,$v := .Items}} {{range $k,$v := .Items}}
{{template "rnSectionItem" $v}} {{template "rnSectionItem" $v}}
{{- end}} {{- end}}
{{- end}}` {{- end}}{{- end}}`
rnSectionBreakingChanges = `{{- if ne .Name ""}} rnSectionBreakingChanges = `{{- if ne .Name ""}}
@ -40,8 +41,10 @@ const (
{{- end}}` {{- end}}`
rnTemplate = `## {{if .Version}}v{{.Version}}{{end}}{{if and .Date .Version}} ({{end}}{{.Date}}{{if and .Version .Date}}){{end}} rnTemplate = `## {{if .Version}}v{{.Version}}{{end}}{{if and .Date .Version}} ({{end}}{{.Date}}{{if and .Version .Date}}){{end}}
{{- template "rnSection" .Sections.feat}} {{- $sections := .Sections }}
{{- template "rnSection" .Sections.fix}} {{- range $key := .Order }}
{{- template "rnSection" (index $sections $key) }}
{{- end}}
{{- template "rnSectionBreakingChanges" .BreakingChanges}} {{- template "rnSectionBreakingChanges" .BreakingChanges}}
` `
) )
@ -101,6 +104,7 @@ func releaseNoteVariables(releasenote ReleaseNote) releaseNoteTemplateVariables
Version: version, Version: version,
Date: date, Date: date,
Sections: releasenote.Sections, Sections: releasenote.Sections,
Order: []string{"feat", "fix", "refactor", "perf", "test", "build", "ci", "chore", "docs", "style"},
BreakingChanges: releasenote.BreakingChanges, BreakingChanges: releasenote.BreakingChanges,
} }
} }

View File

@ -13,6 +13,24 @@ var emptyDateChangelog = `## v1.0.0
` `
var emptyVersionChangelog = `## 2020-05-01 var emptyVersionChangelog = `## 2020-05-01
` `
var fullChangeLog = `## v1.0.0 (2020-05-01)
### Features
- subject text ()
### Bug Fixes
- subject text ()
### Build
- subject text ()
### Breaking Changes
- break change message
`
func TestOutputFormatterImpl_FormatReleaseNote(t *testing.T) { func TestOutputFormatterImpl_FormatReleaseNote(t *testing.T) {
date, _ := time.Parse("2006-01-02", "2020-05-01") date, _ := time.Parse("2006-01-02", "2020-05-01")
@ -25,6 +43,7 @@ func TestOutputFormatterImpl_FormatReleaseNote(t *testing.T) {
{"with date", emptyReleaseNote("1.0.0", date.Truncate(time.Minute)), dateChangelog}, {"with date", emptyReleaseNote("1.0.0", date.Truncate(time.Minute)), dateChangelog},
{"without date", emptyReleaseNote("1.0.0", time.Time{}.Truncate(time.Minute)), emptyDateChangelog}, {"without date", emptyReleaseNote("1.0.0", time.Time{}.Truncate(time.Minute)), emptyDateChangelog},
{"without version", emptyReleaseNote("", date.Truncate(time.Minute)), emptyVersionChangelog}, {"without version", emptyReleaseNote("", date.Truncate(time.Minute)), emptyVersionChangelog},
{"full changelog", fullReleaseNote("1.0.0", date.Truncate(time.Minute)), fullChangeLog},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
@ -45,3 +64,17 @@ func emptyReleaseNote(version string, date time.Time) ReleaseNote {
Date: date, Date: date,
} }
} }
func fullReleaseNote(version string, date time.Time) ReleaseNote {
var v *semver.Version
if version != "" {
v = semver.MustParse(version)
}
sections := map[string]ReleaseNoteSection{
"build": newReleaseNoteSection("Build", []GitCommitLog{commitlog("build", map[string]string{})}),
"feat": newReleaseNoteSection("Features", []GitCommitLog{commitlog("feat", map[string]string{})}),
"fix": newReleaseNoteSection("Bug Fixes", []GitCommitLog{commitlog("fix", map[string]string{})}),
}
return releaseNote(v, date, sections, []string{"break change message"})
}