mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-02-07 18:27:03 +00:00
feat: format markdown in changelog entry
This commit is contained in:
parent
4cb22eae10
commit
929e335a29
6 changed files with 72 additions and 8 deletions
|
|
@ -5,8 +5,10 @@ import (
|
|||
_ "embed"
|
||||
"html/template"
|
||||
"log"
|
||||
"log/slog"
|
||||
|
||||
"github.com/apricote/releaser-pleaser/internal/commitparser"
|
||||
"github.com/apricote/releaser-pleaser/internal/markdown"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -24,7 +26,7 @@ func init() {
|
|||
}
|
||||
}
|
||||
|
||||
func NewChangelogEntry(commits []commitparser.AnalyzedCommit, version, link, prefix, suffix string) (string, error) {
|
||||
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)
|
||||
|
||||
|
|
@ -50,5 +52,11 @@ func NewChangelogEntry(commits []commitparser.AnalyzedCommit, version, link, pre
|
|||
return "", err
|
||||
}
|
||||
|
||||
return changelog.String(), nil
|
||||
formatted, err := markdown.Format(changelog.String())
|
||||
if err != nil {
|
||||
logger.Warn("failed to format changelog entry, using unformatted", "error", err)
|
||||
return changelog.String(), nil
|
||||
}
|
||||
|
||||
return formatted, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,4 +19,4 @@
|
|||
|
||||
{{- if .Suffix }}
|
||||
{{ .Suffix }}
|
||||
{{ end -}}
|
||||
{{ end }}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package changelog
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -34,7 +35,7 @@ func Test_NewChangelogEntry(t *testing.T) {
|
|||
version: "1.0.0",
|
||||
link: "https://example.com/1.0.0",
|
||||
},
|
||||
want: "## [1.0.0](https://example.com/1.0.0)",
|
||||
want: "## [1.0.0](https://example.com/1.0.0)\n",
|
||||
wantErr: assert.NoError,
|
||||
},
|
||||
{
|
||||
|
|
@ -50,7 +51,7 @@ func Test_NewChangelogEntry(t *testing.T) {
|
|||
version: "1.0.0",
|
||||
link: "https://example.com/1.0.0",
|
||||
},
|
||||
want: "## [1.0.0](https://example.com/1.0.0)\n### Features\n\n- Foobar!\n",
|
||||
want: "## [1.0.0](https://example.com/1.0.0)\n\n### Features\n\n- Foobar!\n",
|
||||
wantErr: assert.NoError,
|
||||
},
|
||||
{
|
||||
|
|
@ -66,7 +67,7 @@ func Test_NewChangelogEntry(t *testing.T) {
|
|||
version: "1.0.0",
|
||||
link: "https://example.com/1.0.0",
|
||||
},
|
||||
want: "## [1.0.0](https://example.com/1.0.0)\n### Bug Fixes\n\n- Foobar!\n",
|
||||
want: "## [1.0.0](https://example.com/1.0.0)\n\n### Bug Fixes\n\n- Foobar!\n",
|
||||
wantErr: assert.NoError,
|
||||
},
|
||||
{
|
||||
|
|
@ -100,6 +101,7 @@ func Test_NewChangelogEntry(t *testing.T) {
|
|||
link: "https://example.com/1.0.0",
|
||||
},
|
||||
want: `## [1.0.0](https://example.com/1.0.0)
|
||||
|
||||
### Features
|
||||
|
||||
- Blabla!
|
||||
|
|
@ -127,6 +129,7 @@ func Test_NewChangelogEntry(t *testing.T) {
|
|||
prefix: "### Breaking Changes",
|
||||
},
|
||||
want: `## [1.0.0](https://example.com/1.0.0)
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
### Bug Fixes
|
||||
|
|
@ -150,6 +153,7 @@ func Test_NewChangelogEntry(t *testing.T) {
|
|||
suffix: "### Compatibility\n\nThis version is compatible with flux-compensator v2.2 - v2.9.",
|
||||
},
|
||||
want: `## [1.0.0](https://example.com/1.0.0)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Foobar!
|
||||
|
|
@ -164,7 +168,7 @@ 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(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)
|
||||
if !tt.wantErr(t, err) {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue