From 612928a382e9327630ecde4b9100822db52bd2d6 Mon Sep 17 00:00:00 2001 From: "Jonas L." Date: Thu, 25 Sep 2025 12:25:35 +0200 Subject: [PATCH] fix: using code blocks within release-notes (#275) Increase the number of code blocks backticks to 4 for the release note prefix and suffix, to allow users to embed their own code blocks using only 3 backticks. --- docs/guides/release-notes.md | 8 +- docs/reference/pr-options.md | 8 +- internal/releasepr/releasepr.md.tpl | 8 +- internal/releasepr/releasepr_test.go | 109 +++--------------- internal/testdata/changelog-content.txt | 7 ++ internal/testdata/changelog.txt | 13 +++ .../testdata/description-no-overrides.txt | 28 +++++ internal/testdata/description-overrides.txt | 44 +++++++ internal/testdata/description-prefix.txt | 41 +++++++ internal/testdata/description-suffix.txt | 31 +++++ internal/testdata/prefix.txt | 13 +++ internal/testdata/suffix.txt | 3 + internal/testdata/testdata.go | 19 +++ 13 files changed, 229 insertions(+), 103 deletions(-) create mode 100644 internal/testdata/changelog-content.txt create mode 100644 internal/testdata/changelog.txt create mode 100644 internal/testdata/description-no-overrides.txt create mode 100644 internal/testdata/description-overrides.txt create mode 100644 internal/testdata/description-prefix.txt create mode 100644 internal/testdata/description-suffix.txt create mode 100644 internal/testdata/prefix.txt create mode 100644 internal/testdata/suffix.txt create mode 100644 internal/testdata/testdata.go diff --git a/docs/guides/release-notes.md b/docs/guides/release-notes.md index d994294..599fb52 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 266bd08..1b096d4 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/releasepr/releasepr.md.tpl b/internal/releasepr/releasepr.md.tpl index 6f74aa0..3242c5d 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 346bacb..1f1111b 100644 --- a/internal/releasepr/releasepr_test.go +++ b/internal/releasepr/releasepr_test.go @@ -6,6 +6,7 @@ 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" ) @@ -37,20 +38,24 @@ func TestReleasePullRequest_GetOverrides(t *testing.T) { name: "prefix in description", pr: ReleasePullRequest{ PullRequest: git.PullRequest{ - Description: "```rp-prefix\n## Foo\n\n- Cool thing\n```", + Description: testdata.MustReadFileString(t, "description-prefix.txt"), }, }, - want: ReleaseOverrides{Prefix: "## Foo\n\n- Cool thing"}, + want: ReleaseOverrides{ + Prefix: testdata.MustReadFileString(t, "prefix.txt"), + }, wantErr: assert.NoError, }, { name: "suffix in description", pr: ReleasePullRequest{ PullRequest: git.PullRequest{ - Description: "```rp-suffix\n## Compatibility\n\nNo compatibility guarantees.\n```", + Description: testdata.MustReadFileString(t, "description-suffix.txt"), }, }, - want: ReleaseOverrides{Suffix: "## Compatibility\n\nNo compatibility guarantees."}, + want: ReleaseOverrides{ + Suffix: testdata.MustReadFileString(t, "suffix.txt"), + }, wantErr: assert.NoError, }, } @@ -80,30 +85,10 @@ func TestReleasePullRequest_ChangelogText(t *testing.T) { 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, + name: "with section", + description: testdata.MustReadFileString(t, "changelog.txt"), + want: testdata.MustReadFileString(t, "changelog-content.txt"), + wantErr: assert.NoError, }, } for _, tt := range tests { @@ -178,75 +163,17 @@ func TestReleasePullRequest_SetDescription(t *testing.T) { name: "no overrides", changelogEntry: `## v1.0.0`, overrides: ReleaseOverrides{}, - 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, + want: testdata.MustReadFileString(t, "description-no-overrides.txt"), + wantErr: assert.NoError, }, { name: "existing overrides", changelogEntry: `## v1.0.0`, overrides: ReleaseOverrides{ - Prefix: "This release is awesome!", - Suffix: "Fooo", + Prefix: testdata.MustReadFileString(t, "prefix.txt"), + Suffix: testdata.MustReadFileString(t, "suffix.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 -` + "```" + ` - -
-`, + want: testdata.MustReadFileString(t, "description-overrides.txt"), wantErr: assert.NoError, }, } diff --git a/internal/testdata/changelog-content.txt b/internal/testdata/changelog-content.txt new file mode 100644 index 0000000..3b95e44 --- /dev/null +++ b/internal/testdata/changelog-content.txt @@ -0,0 +1,7 @@ +This is the changelog + +## Awesome + +### New + +#### Changes diff --git a/internal/testdata/changelog.txt b/internal/testdata/changelog.txt new file mode 100644 index 0000000..f77bc5a --- /dev/null +++ b/internal/testdata/changelog.txt @@ -0,0 +1,13 @@ +# 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 new file mode 100644 index 0000000..8a98ae4 --- /dev/null +++ b/internal/testdata/description-no-overrides.txt @@ -0,0 +1,28 @@ + +## 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 new file mode 100644 index 0000000..2fb8249 --- /dev/null +++ b/internal/testdata/description-overrides.txt @@ -0,0 +1,44 @@ + +## 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 + +No compatibility guarantees. +~~~~ + +
diff --git a/internal/testdata/description-prefix.txt b/internal/testdata/description-prefix.txt new file mode 100644 index 0000000..3a30166 --- /dev/null +++ b/internal/testdata/description-prefix.txt @@ -0,0 +1,41 @@ + +## 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 new file mode 100644 index 0000000..4ce7f3b --- /dev/null +++ b/internal/testdata/description-suffix.txt @@ -0,0 +1,31 @@ + +## 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 + +No compatibility guarantees. +~~~~ + +
diff --git a/internal/testdata/prefix.txt b/internal/testdata/prefix.txt new file mode 100644 index 0000000..55271d3 --- /dev/null +++ b/internal/testdata/prefix.txt @@ -0,0 +1,13 @@ +## 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 new file mode 100644 index 0000000..b8d35c0 --- /dev/null +++ b/internal/testdata/suffix.txt @@ -0,0 +1,3 @@ +## Compatibility + +No compatibility guarantees. \ No newline at end of file diff --git a/internal/testdata/testdata.go b/internal/testdata/testdata.go new file mode 100644 index 0000000..28c87d1 --- /dev/null +++ b/internal/testdata/testdata.go @@ -0,0 +1,19 @@ +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) +}