Compare commits

..

1 commit

Author SHA1 Message Date
releaser-pleaser
7463c703de chore(main): release v0.4.0 2024-09-21 11:45:09 +00:00
6 changed files with 34 additions and 72 deletions

View file

@ -7,7 +7,6 @@
- add support for GitLab repositories (#49) - add support for GitLab repositories (#49)
- add shell to container image (#59) - add shell to container image (#59)
- **gitlab**: add CI/CD component (#55) - **gitlab**: add CI/CD component (#55)
- **changelog**: omit version heading in forge release notes
### Bug Fixes ### Bug Fixes

View file

@ -26,37 +26,27 @@ func init() {
} }
} }
func DefaultTemplate() *template.Template { func NewChangelogEntry(logger *slog.Logger, commits []commitparser.AnalyzedCommit, version, link, prefix, suffix string) (string, error) {
return changelogTemplate features := make([]commitparser.AnalyzedCommit, 0)
} fixes := make([]commitparser.AnalyzedCommit, 0)
type Data struct { for _, commit := range commits {
Commits map[string][]commitparser.AnalyzedCommit switch commit.Type {
Version string case "feat":
VersionLink string features = append(features, commit)
Prefix string case "fix":
Suffix string fixes = append(fixes, commit)
}
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 var changelog bytes.Buffer
err := tpl.Execute(&changelog, map[string]any{ err := changelogTemplate.Execute(&changelog, map[string]any{
"Data": data, "Features": features,
"Formatting": formatting, "Fixes": fixes,
"Version": version,
"VersionLink": link,
"Prefix": prefix,
"Suffix": suffix,
}) })
if err != nil { if err != nil {
return "", err return "", err

View file

@ -1,24 +1,22 @@
{{define "entry" -}} ## [{{.Version}}]({{.VersionLink}})
- {{ if .Scope }}**{{.Scope}}**: {{end}}{{.Description}} {{- if .Prefix }}
{{ end }} {{ .Prefix }}
{{- if not .Formatting.HideVersionTitle }}
## [{{.Data.Version}}]({{.Data.VersionLink}})
{{ end -}} {{ end -}}
{{- if .Data.Prefix }} {{- if (gt (len .Features) 0) }}
{{ .Data.Prefix }}
{{ end -}}
{{- with .Data.Commits.feat }}
### Features ### Features
{{ range . -}}{{template "entry" .}}{{end}} {{ range .Features -}}
- {{ if .Scope }}**{{.Scope}}**: {{end}}{{.Description}}
{{ end -}}
{{- end -}} {{- end -}}
{{- with .Data.Commits.fix }} {{- if (gt (len .Fixes) 0) }}
### Bug Fixes ### Bug Fixes
{{ range . -}}{{template "entry" .}}{{end}} {{ range .Fixes -}}
- {{ if .Scope }}**{{.Scope}}**: {{end}}{{.Description}}
{{ end -}}
{{- end -}} {{- end -}}
{{- if .Data.Suffix }} {{- if .Suffix }}
{{ .Data.Suffix }} {{ .Suffix }}
{{ end }} {{ end }}

View file

@ -168,8 +168,7 @@ This version is compatible with flux-compensator v2.2 - v2.9.
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
data := New(commitparser.ByType(tt.args.analyzedCommits), tt.args.version, tt.args.link, tt.args.prefix, tt.args.suffix) got, err := NewChangelogEntry(slog.Default(), 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) { if !tt.wantErr(t, err) {
return return
} }

View file

@ -15,18 +15,3 @@ type AnalyzedCommit struct {
Scope *string Scope *string
BreakingChange bool 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
}

View file

@ -243,9 +243,7 @@ func (rp *ReleaserPleaser) runReconcileReleasePR(ctx context.Context) error {
return err return err
} }
changelogData := changelog.New(commitparser.ByType(analyzedCommits), nextVersion, rp.forge.ReleaseURL(nextVersion), releaseOverrides.Prefix, releaseOverrides.Suffix) changelogEntry, err := changelog.NewChangelogEntry(logger, analyzedCommits, nextVersion, rp.forge.ReleaseURL(nextVersion), releaseOverrides.Prefix, releaseOverrides.Suffix)
changelogEntry, err := changelog.Entry(logger, changelog.DefaultTemplate(), changelogData, changelog.Formatting{})
if err != nil { if err != nil {
return fmt.Errorf("failed to build changelog entry: %w", err) return fmt.Errorf("failed to build changelog entry: %w", err)
} }
@ -291,16 +289,9 @@ func (rp *ReleaserPleaser) runReconcileReleasePR(ctx context.Context) error {
logger.InfoContext(ctx, "file content is already up-to-date in remote branch, skipping push") logger.InfoContext(ctx, "file content is already up-to-date in remote branch, skipping push")
} }
// We do not need the version title here. In the pull request the version is available from the title, and in the
// release on the Forge its usually in a heading somewhere above the text.
changelogEntryPullRequest, err := changelog.Entry(logger, changelog.DefaultTemplate(), changelogData, changelog.Formatting{HideVersionTitle: true})
if err != nil {
return fmt.Errorf("failed to build pull request changelog entry: %w", err)
}
// Open/Update PR // Open/Update PR
if pr == nil { if pr == nil {
pr, err = releasepr.NewReleasePullRequest(rpBranch, rp.targetBranch, nextVersion, changelogEntryPullRequest) pr, err = releasepr.NewReleasePullRequest(rpBranch, rp.targetBranch, nextVersion, changelogEntry)
if err != nil { if err != nil {
return err return err
} }
@ -317,7 +308,7 @@ func (rp *ReleaserPleaser) runReconcileReleasePR(ctx context.Context) error {
if err != nil { if err != nil {
return err return err
} }
err = pr.SetDescription(changelogEntryPullRequest, overrides) err = pr.SetDescription(changelogEntry, overrides)
if err != nil { if err != nil {
return err return err
} }