mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-01-13 13:21:00 +00:00
feat(changelog): omit version heading in forge release notes
The forge ui usually shows the release name right above the description, so this removes an unecessary duplicate bit of information. In addition this also cleans up the changelog interface a bit and moves functionality where it belongs. Prepares a bit for custom changelogs in the future. Closes #32
This commit is contained in:
parent
997b6492de
commit
2621c48d75
5 changed files with 71 additions and 34 deletions
|
|
@ -26,27 +26,37 @@ func init() {
|
|||
}
|
||||
}
|
||||
|
||||
func NewChangelogEntry(logger *slog.Logger, commits []commitparser.AnalyzedCommit, version, link, prefix, suffix string) (string, error) {
|
||||
features := make([]commitparser.AnalyzedCommit, 0)
|
||||
fixes := make([]commitparser.AnalyzedCommit, 0)
|
||||
func DefaultTemplate() *template.Template {
|
||||
return changelogTemplate
|
||||
}
|
||||
|
||||
for _, commit := range commits {
|
||||
switch commit.Type {
|
||||
case "feat":
|
||||
features = append(features, commit)
|
||||
case "fix":
|
||||
fixes = append(fixes, commit)
|
||||
}
|
||||
type Data struct {
|
||||
Commits map[string][]commitparser.AnalyzedCommit
|
||||
Version string
|
||||
VersionLink string
|
||||
Prefix string
|
||||
Suffix string
|
||||
}
|
||||
|
||||
func New(commits map[string][]commitparser.AnalyzedCommit, version, versionLink, prefix, suffix string) Data {
|
||||
return Data{
|
||||
Commits: commits,
|
||||
Version: version,
|
||||
VersionLink: versionLink,
|
||||
Prefix: prefix,
|
||||
Suffix: suffix,
|
||||
}
|
||||
}
|
||||
|
||||
type Formatting struct {
|
||||
HideVersionTitle bool
|
||||
}
|
||||
|
||||
func Entry(logger *slog.Logger, tpl *template.Template, data Data, formatting Formatting) (string, error) {
|
||||
var changelog bytes.Buffer
|
||||
err := changelogTemplate.Execute(&changelog, map[string]any{
|
||||
"Features": features,
|
||||
"Fixes": fixes,
|
||||
"Version": version,
|
||||
"VersionLink": link,
|
||||
"Prefix": prefix,
|
||||
"Suffix": suffix,
|
||||
err := tpl.Execute(&changelog, map[string]any{
|
||||
"Data": data,
|
||||
"Formatting": formatting,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
|
|||
|
|
@ -1,22 +1,24 @@
|
|||
## [{{.Version}}]({{.VersionLink}})
|
||||
{{- if .Prefix }}
|
||||
{{ .Prefix }}
|
||||
{{define "entry" -}}
|
||||
- {{ if .Scope }}**{{.Scope}}**: {{end}}{{.Description}}
|
||||
{{ end }}
|
||||
|
||||
{{- if not .Formatting.HideVersionTitle }}
|
||||
## [{{.Data.Version}}]({{.Data.VersionLink}})
|
||||
{{ end -}}
|
||||
{{- if (gt (len .Features) 0) }}
|
||||
{{- if .Data.Prefix }}
|
||||
{{ .Data.Prefix }}
|
||||
{{ end -}}
|
||||
{{- with .Data.Commits.feat }}
|
||||
### Features
|
||||
|
||||
{{ range .Features -}}
|
||||
- {{ if .Scope }}**{{.Scope}}**: {{end}}{{.Description}}
|
||||
{{ end -}}
|
||||
{{ range . -}}{{template "entry" .}}{{end}}
|
||||
{{- end -}}
|
||||
{{- if (gt (len .Fixes) 0) }}
|
||||
{{- with .Data.Commits.fix }}
|
||||
### Bug Fixes
|
||||
|
||||
{{ range .Fixes -}}
|
||||
- {{ if .Scope }}**{{.Scope}}**: {{end}}{{.Description}}
|
||||
{{ end -}}
|
||||
{{ range . -}}{{template "entry" .}}{{end}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if .Suffix }}
|
||||
{{ .Suffix }}
|
||||
{{- if .Data.Suffix }}
|
||||
{{ .Data.Suffix }}
|
||||
{{ end }}
|
||||
|
|
|
|||
|
|
@ -168,7 +168,8 @@ This version is compatible with flux-compensator v2.2 - v2.9.
|
|||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := NewChangelogEntry(slog.Default(), tt.args.analyzedCommits, tt.args.version, tt.args.link, tt.args.prefix, tt.args.suffix)
|
||||
data := New(commitparser.ByType(tt.args.analyzedCommits), tt.args.version, tt.args.link, tt.args.prefix, tt.args.suffix)
|
||||
got, err := Entry(slog.Default(), DefaultTemplate(), data, Formatting{})
|
||||
if !tt.wantErr(t, err) {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,3 +15,18 @@ type AnalyzedCommit struct {
|
|||
Scope *string
|
||||
BreakingChange bool
|
||||
}
|
||||
|
||||
// ByType groups the Commits by the type field. Used by the Changelog.
|
||||
func ByType(in []AnalyzedCommit) map[string][]AnalyzedCommit {
|
||||
out := map[string][]AnalyzedCommit{}
|
||||
|
||||
for _, commit := range in {
|
||||
if out[commit.Type] == nil {
|
||||
out[commit.Type] = make([]AnalyzedCommit, 0, 1)
|
||||
}
|
||||
|
||||
out[commit.Type] = append(out[commit.Type], commit)
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue