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.
This commit is contained in:
Jonas L. 2025-09-25 12:25:35 +02:00 committed by GitHub
parent 93bb42e781
commit 612928a382
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 229 additions and 103 deletions

View file

@ -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. 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 > ### Prefix
> >
> This will be shown as the Prefix. > This will be shown as the Prefix.
> ``` > ~~~~
> >
> ```rp-suffix > ~~~~rp-suffix
> ### Suffix > ### Suffix
> >
> This will be shown as the 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`). To match the style of the auto-generated release notes, you should start any headings at level 3 (`### Title`).

View file

@ -30,17 +30,17 @@ Any text in code blocks with these languages is being added to the start or end
**Examples**: **Examples**:
```rp-prefix ~~~~rp-prefix
#### Awesome new feature! #### Awesome new feature!
This text is at the start of the release notes. This text is at the start of the release notes.
``` ~~~~
```rp-suffix ~~~~rp-suffix
#### Version Compatibility #### Version Compatibility
And this at the end. And this at the end.
``` ~~~~
### Status ### Status

View file

@ -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. This will be added to the start of the release notes.
```rp-prefix ~~~~rp-prefix
{{- if .Overrides.Prefix }} {{- if .Overrides.Prefix }}
{{ .Overrides.Prefix }}{{ end }} {{ .Overrides.Prefix }}{{ end }}
``` ~~~~
### Suffix / End ### Suffix / End
This will be added to the end of the release notes. This will be added to the end of the release notes.
```rp-suffix ~~~~rp-suffix
{{- if .Overrides.Suffix }} {{- if .Overrides.Suffix }}
{{ .Overrides.Suffix }}{{ end }} {{ .Overrides.Suffix }}{{ end }}
``` ~~~~
</details> </details>

View file

@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/apricote/releaser-pleaser/internal/git" "github.com/apricote/releaser-pleaser/internal/git"
"github.com/apricote/releaser-pleaser/internal/testdata"
"github.com/apricote/releaser-pleaser/internal/versioning" "github.com/apricote/releaser-pleaser/internal/versioning"
) )
@ -37,20 +38,24 @@ func TestReleasePullRequest_GetOverrides(t *testing.T) {
name: "prefix in description", name: "prefix in description",
pr: ReleasePullRequest{ pr: ReleasePullRequest{
PullRequest: git.PullRequest{ 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, wantErr: assert.NoError,
}, },
{ {
name: "suffix in description", name: "suffix in description",
pr: ReleasePullRequest{ pr: ReleasePullRequest{
PullRequest: git.PullRequest{ 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, wantErr: assert.NoError,
}, },
} }
@ -80,30 +85,10 @@ func TestReleasePullRequest_ChangelogText(t *testing.T) {
wantErr: assert.NoError, wantErr: assert.NoError,
}, },
{ {
name: "with section", name: "with section",
description: `# Foobar description: testdata.MustReadFileString(t, "changelog.txt"),
want: testdata.MustReadFileString(t, "changelog-content.txt"),
<!-- section-start changelog --> wantErr: assert.NoError,
This is the changelog
## Awesome
### New
#### Changes
<!-- section-end changelog -->
Suffix Things
`,
want: `This is the changelog
## Awesome
### New
#### Changes
`,
wantErr: assert.NoError,
}, },
} }
for _, tt := range tests { for _, tt := range tests {
@ -178,75 +163,17 @@ func TestReleasePullRequest_SetDescription(t *testing.T) {
name: "no overrides", name: "no overrides",
changelogEntry: `## v1.0.0`, changelogEntry: `## v1.0.0`,
overrides: ReleaseOverrides{}, overrides: ReleaseOverrides{},
want: `<!-- section-start changelog --> want: testdata.MustReadFileString(t, "description-no-overrides.txt"),
## v1.0.0 wantErr: assert.NoError,
<!-- section-end changelog -->
---
<details>
<summary><h4>PR by <a href="https://github.com/apricote/releaser-pleaser">releaser-pleaser</a> 🤖</h4></summary>
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
` + "```" + `
</details>
`,
wantErr: assert.NoError,
}, },
{ {
name: "existing overrides", name: "existing overrides",
changelogEntry: `## v1.0.0`, changelogEntry: `## v1.0.0`,
overrides: ReleaseOverrides{ overrides: ReleaseOverrides{
Prefix: "This release is awesome!", Prefix: testdata.MustReadFileString(t, "prefix.txt"),
Suffix: "Fooo", Suffix: testdata.MustReadFileString(t, "suffix.txt"),
}, },
want: `<!-- section-start changelog --> want: testdata.MustReadFileString(t, "description-overrides.txt"),
## v1.0.0
<!-- section-end changelog -->
---
<details>
<summary><h4>PR by <a href="https://github.com/apricote/releaser-pleaser">releaser-pleaser</a> 🤖</h4></summary>
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
` + "```" + `
</details>
`,
wantErr: assert.NoError, wantErr: assert.NoError,
}, },
} }

View file

@ -0,0 +1,7 @@
This is the changelog
## Awesome
### New
#### Changes

13
internal/testdata/changelog.txt vendored Normal file
View file

@ -0,0 +1,13 @@
# Foobar
<!-- section-start changelog -->
This is the changelog
## Awesome
### New
#### Changes
<!-- section-end changelog -->
Suffix Things

View file

@ -0,0 +1,28 @@
<!-- section-start changelog -->
## v1.0.0
<!-- section-end changelog -->
---
<details>
<summary><h4>PR by <a href="https://github.com/apricote/releaser-pleaser">releaser-pleaser</a> 🤖</h4></summary>
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
~~~~
</details>

View file

@ -0,0 +1,44 @@
<!-- section-start changelog -->
## v1.0.0
<!-- section-end changelog -->
---
<details>
<summary><h4>PR by <a href="https://github.com/apricote/releaser-pleaser">releaser-pleaser</a> 🤖</h4></summary>
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.
~~~~
</details>

View file

@ -0,0 +1,41 @@
<!-- section-start changelog -->
## v1.0.0
<!-- section-end changelog -->
---
<details>
<summary><h4>PR by <a href="https://github.com/apricote/releaser-pleaser">releaser-pleaser</a> 🤖</h4></summary>
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
~~~~
</details>

View file

@ -0,0 +1,31 @@
<!-- section-start changelog -->
## v1.0.0
<!-- section-end changelog -->
---
<details>
<summary><h4>PR by <a href="https://github.com/apricote/releaser-pleaser">releaser-pleaser</a> 🤖</h4></summary>
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.
~~~~
</details>

13
internal/testdata/prefix.txt vendored Normal file
View file

@ -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
}
```

3
internal/testdata/suffix.txt vendored Normal file
View file

@ -0,0 +1,3 @@
## Compatibility
No compatibility guarantees.

19
internal/testdata/testdata.go vendored Normal file
View file

@ -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)
}