mirror of
https://github.com/goreleaser/goreleaser.git
synced 2024-12-31 01:53:50 +02:00
fix: changelog is too long (#2661)
Signed-off-by: Engin Diri <engin.diri@mail.schwarz>
This commit is contained in:
parent
9af17a49ad
commit
c958e4cc5e
@ -12,6 +12,13 @@ import (
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
)
|
||||
|
||||
const (
|
||||
// maxReleaseBodyLength defines the max characters size of the body
|
||||
maxReleaseBodyLength = 125000
|
||||
// ellipsis to be used when release notes body is too long
|
||||
ellipsis = "..."
|
||||
)
|
||||
|
||||
// ErrNotImplemented is returned when a client does not implement certain feature.
|
||||
var ErrNotImplemented = fmt.Errorf("not implemented")
|
||||
|
||||
@ -83,6 +90,13 @@ func NewIfToken(ctx *context.Context, cli Client, token string) (Client, error)
|
||||
return newWithToken(ctx, token)
|
||||
}
|
||||
|
||||
func truncateReleaseBody(body string) string {
|
||||
if len(body) > maxReleaseBodyLength {
|
||||
body = body[1:(maxReleaseBodyLength-len(ellipsis))] + ellipsis
|
||||
}
|
||||
return body
|
||||
}
|
||||
|
||||
// ErrNoMilestoneFound is an error when no milestone is found.
|
||||
type ErrNoMilestoneFound struct {
|
||||
Title string
|
||||
|
@ -1,6 +1,7 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
@ -59,6 +60,18 @@ func TestClientNewGitLab(t *testing.T) {
|
||||
require.True(t, ok)
|
||||
}
|
||||
|
||||
func TestCheckBodyMaxLength(t *testing.T) {
|
||||
letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
b := make([]rune, maxReleaseBodyLength)
|
||||
for i := range b {
|
||||
b[i] = letters[rand.Intn(len(letters))]
|
||||
}
|
||||
ctx := context.New(config.Project{})
|
||||
ctx.ReleaseNotes = string(b)
|
||||
out := truncateReleaseBody(string(b))
|
||||
require.Len(t, out, maxReleaseBodyLength)
|
||||
}
|
||||
|
||||
func TestNewIfToken(t *testing.T) {
|
||||
t.Run("valid", func(t *testing.T) {
|
||||
ctx := &context.Context{
|
||||
|
@ -207,6 +207,9 @@ func (c *githubClient) CreateRelease(ctx *context.Context, body string) (string,
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Truncate the release notes if it's too long (github doesn't allow more than 125000 characters)
|
||||
body = truncateReleaseBody(body)
|
||||
|
||||
data := &github.RepositoryRelease{
|
||||
Name: github.String(title),
|
||||
TagName: github.String(ctx.Git.CurrentTag),
|
||||
|
Loading…
Reference in New Issue
Block a user