mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-20 23:46:49 +00:00
fixes #914
This commit is contained in:
parent
78fa97d53c
commit
833b5af087
3 changed files with 64 additions and 35 deletions
|
@ -32,11 +32,16 @@ type Build struct {
|
|||
Verified bool `json:"verified" meddler:"build_verified"` // deprecate
|
||||
Reviewer string `json:"reviewed_by" meddler:"build_reviewer"`
|
||||
Reviewed int64 `json:"reviewed_at" meddler:"build_reviewed"`
|
||||
// Jobs []*Job `json:"jobs,omitempty" meddler:"-"`
|
||||
Procs []*Proc `json:"procs,omitempty" meddler:"-"`
|
||||
}
|
||||
|
||||
type BuildGroup struct {
|
||||
Date string
|
||||
Builds []*Build
|
||||
// Trim trims string values that would otherwise exceed
|
||||
// the database column sizes and fail to insert.
|
||||
func (b *Build) Trim() {
|
||||
if len(b.Title) > 500 {
|
||||
b.Title = b.Title[:500]
|
||||
}
|
||||
if len(b.Message) > 500 {
|
||||
b.Message = b.Message[:500]
|
||||
}
|
||||
}
|
||||
|
|
23
model/build_test.go
Normal file
23
model/build_test.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBuildTrim(t *testing.T) {
|
||||
d := make([]byte, 1000)
|
||||
rand.Read(d)
|
||||
|
||||
b := Build{}
|
||||
b.Message = fmt.Sprintf("%X", d)
|
||||
|
||||
if len(b.Message) != 2000 {
|
||||
t.Errorf("Failed to generate 2000 byte test string")
|
||||
}
|
||||
b.Trim()
|
||||
if len(b.Message) != 500 {
|
||||
t.Errorf("Failed to trim text string to 500 bytes")
|
||||
}
|
||||
}
|
|
@ -197,6 +197,7 @@ func PostHook(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
build.Trim()
|
||||
err = store.CreateBuild(c, build, build.Procs...)
|
||||
if err != nil {
|
||||
logrus.Errorf("failure to save commit for %s. %s", repo.FullName, err)
|
||||
|
|
Loading…
Reference in a new issue