diff --git a/docs/guides/release-notes.md b/docs/guides/release-notes.md index 599fb52..d994294 100644 --- a/docs/guides/release-notes.md +++ b/docs/guides/release-notes.md @@ -43,17 +43,17 @@ The release pull request description has text fields where maintainers can add t When you edit the description, make sure to put your desired content into the code blocks named `rp-prefix` and `rp-suffix`. Only the content of these blocks is considered. -> ~~~~rp-prefix +> ```rp-prefix > ### Prefix > > This will be shown as the Prefix. -> ~~~~ +> ``` > -> ~~~~rp-suffix +> ```rp-suffix > ### Suffix > > This will be shown as the Suffix. -> ~~~~ +> ``` To match the style of the auto-generated release notes, you should start any headings at level 3 (`### Title`). diff --git a/docs/reference/pr-options.md b/docs/reference/pr-options.md index 1b096d4..266bd08 100644 --- a/docs/reference/pr-options.md +++ b/docs/reference/pr-options.md @@ -30,17 +30,17 @@ Any text in code blocks with these languages is being added to the start or end **Examples**: - ~~~~rp-prefix + ```rp-prefix #### Awesome new feature! This text is at the start of the release notes. - ~~~~ + ``` - ~~~~rp-suffix + ```rp-suffix #### Version Compatibility And this at the end. - ~~~~ + ``` ### Status diff --git a/internal/changelog/changelog.go b/internal/changelog/changelog.go index dda751a..d6386b8 100644 --- a/internal/changelog/changelog.go +++ b/internal/changelog/changelog.go @@ -3,9 +3,9 @@ package changelog import ( "bytes" _ "embed" + "html/template" "log" "log/slog" - "text/template" "github.com/apricote/releaser-pleaser/internal/commitparser" "github.com/apricote/releaser-pleaser/internal/markdown" diff --git a/internal/changelog/changelog_test.go b/internal/changelog/changelog_test.go index c2bbf71..e4fe52f 100644 --- a/internal/changelog/changelog_test.go +++ b/internal/changelog/changelog_test.go @@ -8,7 +8,6 @@ import ( "github.com/apricote/releaser-pleaser/internal/commitparser" "github.com/apricote/releaser-pleaser/internal/git" - "github.com/apricote/releaser-pleaser/internal/testdata" ) func ptr[T any](input T) *T { @@ -144,9 +143,16 @@ func Test_NewChangelogEntry(t *testing.T) { }, version: "1.0.0", link: "https://example.com/1.0.0", - prefix: testdata.MustReadFileString(t, "prefix.txt"), + prefix: "### Breaking Changes", }, - want: testdata.MustReadFileString(t, "changelog-entry-prefix.txt"), + want: `## [1.0.0](https://example.com/1.0.0) + +### Breaking Changes + +### Bug Fixes + +- Foobar! +`, wantErr: assert.NoError, }, { @@ -161,9 +167,18 @@ func Test_NewChangelogEntry(t *testing.T) { }, version: "1.0.0", link: "https://example.com/1.0.0", - suffix: testdata.MustReadFileString(t, "suffix.txt"), + suffix: "### Compatibility\n\nThis version is compatible with flux-compensator v2.2 - v2.9.", }, - want: testdata.MustReadFileString(t, "changelog-entry-suffix.txt"), + want: `## [1.0.0](https://example.com/1.0.0) + +### Bug Fixes + +- Foobar! + +### Compatibility + +This version is compatible with flux-compensator v2.2 - v2.9. +`, wantErr: assert.NoError, }, } diff --git a/internal/releasepr/releasepr.md.tpl b/internal/releasepr/releasepr.md.tpl index 3242c5d..6f74aa0 100644 --- a/internal/releasepr/releasepr.md.tpl +++ b/internal/releasepr/releasepr.md.tpl @@ -15,18 +15,18 @@ If you want to modify the proposed release, add you overrides here. You can lear This will be added to the start of the release notes. -~~~~rp-prefix +```rp-prefix {{- if .Overrides.Prefix }} {{ .Overrides.Prefix }}{{ end }} -~~~~ +``` ### Suffix / End This will be added to the end of the release notes. -~~~~rp-suffix +```rp-suffix {{- if .Overrides.Suffix }} {{ .Overrides.Suffix }}{{ end }} -~~~~ +``` diff --git a/internal/releasepr/releasepr_test.go b/internal/releasepr/releasepr_test.go index 1f1111b..346bacb 100644 --- a/internal/releasepr/releasepr_test.go +++ b/internal/releasepr/releasepr_test.go @@ -6,7 +6,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/apricote/releaser-pleaser/internal/git" - "github.com/apricote/releaser-pleaser/internal/testdata" "github.com/apricote/releaser-pleaser/internal/versioning" ) @@ -38,24 +37,20 @@ func TestReleasePullRequest_GetOverrides(t *testing.T) { name: "prefix in description", pr: ReleasePullRequest{ PullRequest: git.PullRequest{ - Description: testdata.MustReadFileString(t, "description-prefix.txt"), + Description: "```rp-prefix\n## Foo\n\n- Cool thing\n```", }, }, - want: ReleaseOverrides{ - Prefix: testdata.MustReadFileString(t, "prefix.txt"), - }, + want: ReleaseOverrides{Prefix: "## Foo\n\n- Cool thing"}, wantErr: assert.NoError, }, { name: "suffix in description", pr: ReleasePullRequest{ PullRequest: git.PullRequest{ - Description: testdata.MustReadFileString(t, "description-suffix.txt"), + Description: "```rp-suffix\n## Compatibility\n\nNo compatibility guarantees.\n```", }, }, - want: ReleaseOverrides{ - Suffix: testdata.MustReadFileString(t, "suffix.txt"), - }, + want: ReleaseOverrides{Suffix: "## Compatibility\n\nNo compatibility guarantees."}, wantErr: assert.NoError, }, } @@ -85,10 +80,30 @@ func TestReleasePullRequest_ChangelogText(t *testing.T) { wantErr: assert.NoError, }, { - name: "with section", - description: testdata.MustReadFileString(t, "changelog.txt"), - want: testdata.MustReadFileString(t, "changelog-content.txt"), - wantErr: assert.NoError, + name: "with section", + description: `# Foobar + + +This is the changelog + +## Awesome + +### New + +#### Changes + + +Suffix Things +`, + want: `This is the changelog + +## Awesome + +### New + +#### Changes +`, + wantErr: assert.NoError, }, } for _, tt := range tests { @@ -163,17 +178,75 @@ func TestReleasePullRequest_SetDescription(t *testing.T) { name: "no overrides", changelogEntry: `## v1.0.0`, overrides: ReleaseOverrides{}, - want: testdata.MustReadFileString(t, "description-no-overrides.txt"), - wantErr: assert.NoError, + want: ` +## v1.0.0 + + +--- + +
+

PR by releaser-pleaser 🤖

+ +If you want to modify the proposed release, add you overrides here. You can learn more about the options in the docs. + +## Release Notes + +### Prefix / Start + +This will be added to the start of the release notes. + +` + "```" + `rp-prefix +` + "```" + ` + +### Suffix / End + +This will be added to the end of the release notes. + +` + "```" + `rp-suffix +` + "```" + ` + +
+`, + wantErr: assert.NoError, }, { name: "existing overrides", changelogEntry: `## v1.0.0`, overrides: ReleaseOverrides{ - Prefix: testdata.MustReadFileString(t, "prefix.txt"), - Suffix: testdata.MustReadFileString(t, "suffix.txt"), + Prefix: "This release is awesome!", + Suffix: "Fooo", }, - want: testdata.MustReadFileString(t, "description-overrides.txt"), + want: ` +## v1.0.0 + + +--- + +
+

PR by releaser-pleaser 🤖

+ +If you want to modify the proposed release, add you overrides here. You can learn more about the options in the docs. + +## Release Notes + +### Prefix / Start + +This will be added to the start of the release notes. + +` + "```" + `rp-prefix +This release is awesome! +` + "```" + ` + +### Suffix / End + +This will be added to the end of the release notes. + +` + "```" + `rp-suffix +Fooo +` + "```" + ` + +
+`, wantErr: assert.NoError, }, } diff --git a/internal/testdata/changelog-content.txt b/internal/testdata/changelog-content.txt deleted file mode 100644 index 3b95e44..0000000 --- a/internal/testdata/changelog-content.txt +++ /dev/null @@ -1,7 +0,0 @@ -This is the changelog - -## Awesome - -### New - -#### Changes diff --git a/internal/testdata/changelog-entry-prefix.txt b/internal/testdata/changelog-entry-prefix.txt deleted file mode 100644 index 186d04a..0000000 --- a/internal/testdata/changelog-entry-prefix.txt +++ /dev/null @@ -1,19 +0,0 @@ -## [1.0.0](https://example.com/1.0.0) - -## Foo - -- Cool thing - -```go -// Some code example -func IsPositive(number int) error { - if number < 0 { - return fmt.Errorf("number %d is negative", number) - } - return nil -} -``` - -### Bug Fixes - -- Foobar! diff --git a/internal/testdata/changelog-entry-suffix.txt b/internal/testdata/changelog-entry-suffix.txt deleted file mode 100644 index 91bbb05..0000000 --- a/internal/testdata/changelog-entry-suffix.txt +++ /dev/null @@ -1,9 +0,0 @@ -## [1.0.0](https://example.com/1.0.0) - -### Bug Fixes - -- Foobar! - -## Compatibility - -This version is compatible with flux-compensator v2.2 - v2.9. diff --git a/internal/testdata/changelog.txt b/internal/testdata/changelog.txt deleted file mode 100644 index f77bc5a..0000000 --- a/internal/testdata/changelog.txt +++ /dev/null @@ -1,13 +0,0 @@ -# Foobar - - -This is the changelog - -## Awesome - -### New - -#### Changes - - -Suffix Things \ No newline at end of file diff --git a/internal/testdata/description-no-overrides.txt b/internal/testdata/description-no-overrides.txt deleted file mode 100644 index 8a98ae4..0000000 --- a/internal/testdata/description-no-overrides.txt +++ /dev/null @@ -1,28 +0,0 @@ - -## v1.0.0 - - ---- - -
-

PR by releaser-pleaser 🤖

- -If you want to modify the proposed release, add you overrides here. You can learn more about the options in the docs. - -## Release Notes - -### Prefix / Start - -This will be added to the start of the release notes. - -~~~~rp-prefix -~~~~ - -### Suffix / End - -This will be added to the end of the release notes. - -~~~~rp-suffix -~~~~ - -
diff --git a/internal/testdata/description-overrides.txt b/internal/testdata/description-overrides.txt deleted file mode 100644 index 5a1db7e..0000000 --- a/internal/testdata/description-overrides.txt +++ /dev/null @@ -1,44 +0,0 @@ - -## v1.0.0 - - ---- - -
-

PR by releaser-pleaser 🤖

- -If you want to modify the proposed release, add you overrides here. You can learn more about the options in the docs. - -## Release Notes - -### Prefix / Start - -This will be added to the start of the release notes. - -~~~~rp-prefix -## Foo - -- Cool thing - -```go -// Some code example -func IsPositive(number int) error { - if number < 0 { - return fmt.Errorf("number %d is negative", number) - } - return nil -} -``` -~~~~ - -### Suffix / End - -This will be added to the end of the release notes. - -~~~~rp-suffix -## Compatibility - -This version is compatible with flux-compensator v2.2 - v2.9. -~~~~ - -
diff --git a/internal/testdata/description-prefix.txt b/internal/testdata/description-prefix.txt deleted file mode 100644 index 3a30166..0000000 --- a/internal/testdata/description-prefix.txt +++ /dev/null @@ -1,41 +0,0 @@ - -## v1.0.0 - - ---- - -
-

PR by releaser-pleaser 🤖

- -If you want to modify the proposed release, add you overrides here. You can learn more about the options in the docs. - -## Release Notes - -### Prefix / Start - -This will be added to the start of the release notes. - -~~~~rp-prefix -## Foo - -- Cool thing - -```go -// Some code example -func IsPositive(number int) error { - if number < 0 { - return fmt.Errorf("number %d is negative", number) - } - return nil -} -``` -~~~~ - -### Suffix / End - -This will be added to the end of the release notes. - -~~~~rp-suffix -~~~~ - -
diff --git a/internal/testdata/description-suffix.txt b/internal/testdata/description-suffix.txt deleted file mode 100644 index d0a1596..0000000 --- a/internal/testdata/description-suffix.txt +++ /dev/null @@ -1,31 +0,0 @@ - -## v1.0.0 - - ---- - -
-

PR by releaser-pleaser 🤖

- -If you want to modify the proposed release, add you overrides here. You can learn more about the options in the docs. - -## Release Notes - -### Prefix / Start - -This will be added to the start of the release notes. - -~~~~rp-prefix -~~~~ - -### Suffix / End - -This will be added to the end of the release notes. - -~~~~rp-suffix -## Compatibility - -This version is compatible with flux-compensator v2.2 - v2.9. -~~~~ - -
diff --git a/internal/testdata/prefix.txt b/internal/testdata/prefix.txt deleted file mode 100644 index 55271d3..0000000 --- a/internal/testdata/prefix.txt +++ /dev/null @@ -1,13 +0,0 @@ -## Foo - -- Cool thing - -```go -// Some code example -func IsPositive(number int) error { - if number < 0 { - return fmt.Errorf("number %d is negative", number) - } - return nil -} -``` \ No newline at end of file diff --git a/internal/testdata/suffix.txt b/internal/testdata/suffix.txt deleted file mode 100644 index 3fc6656..0000000 --- a/internal/testdata/suffix.txt +++ /dev/null @@ -1,3 +0,0 @@ -## Compatibility - -This version is compatible with flux-compensator v2.2 - v2.9. \ No newline at end of file diff --git a/internal/testdata/testdata.go b/internal/testdata/testdata.go deleted file mode 100644 index 28c87d1..0000000 --- a/internal/testdata/testdata.go +++ /dev/null @@ -1,19 +0,0 @@ -package testdata - -import ( - "embed" - "testing" -) - -//go:embed *.txt -var testdata embed.FS - -func MustReadFileString(t *testing.T, name string) string { - t.Helper() - - content, err := testdata.ReadFile(name) - if err != nil { - t.Fatal(err) - } - return string(content) -}