Skip to content

Commit 91b5c27

Browse files
committed
Trim title before insert/update to database to match the size requirements of database
1 parent 0aedb03 commit 91b5c27

File tree

6 files changed

+11
-0
lines changed

6 files changed

+11
-0
lines changed

models/actions/run.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ func CancelPreviousJobs(ctx context.Context, repoID int64, ref, workflowID strin
261261
}
262262

263263
// InsertRun inserts a run
264+
// The title will be cut off at 255 characters if it's longer than 255 characters.
264265
func InsertRun(ctx context.Context, run *ActionRun, jobs []*jobparser.SingleWorkflow) error {
265266
ctx, committer, err := db.TxContext(ctx)
266267
if err != nil {
@@ -273,6 +274,7 @@ func InsertRun(ctx context.Context, run *ActionRun, jobs []*jobparser.SingleWork
273274
return err
274275
}
275276
run.Index = index
277+
run.Title, _ = util.SplitStringAtByteN(run.Title, 255)
276278

277279
if err := db.Insert(ctx, run); err != nil {
278280
return err

models/issues/issue_update.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"code.gitea.io/gitea/modules/references"
2222
api "code.gitea.io/gitea/modules/structs"
2323
"code.gitea.io/gitea/modules/timeutil"
24+
"code.gitea.io/gitea/modules/util"
2425

2526
"xorm.io/builder"
2627
)
@@ -386,6 +387,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue
386387
}
387388

388389
// NewIssue creates new issue with labels for repository.
390+
// The title will be cut off at 255 characters if it's longer than 255 characters.
389391
func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) {
390392
ctx, committer, err := db.TxContext(ctx)
391393
if err != nil {
@@ -399,6 +401,7 @@ func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *Issue, la
399401
}
400402

401403
issue.Index = idx
404+
issue.Title, _ = util.SplitStringAtByteN(issue.Title, 255)
402405

403406
if err = NewIssueWithIndex(ctx, issue.Poster, NewIssueOptions{
404407
Repo: repo,

models/issues/pull.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *Iss
572572
}
573573

574574
issue.Index = idx
575+
issue.Title, _ = util.SplitStringAtByteN(issue.Title, 255)
575576

576577
if err = NewIssueWithIndex(ctx, issue.Poster, NewIssueOptions{
577578
Repo: repo,

models/project/project.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ func GetSearchOrderByBySortType(sortType string) db.SearchOrderBy {
242242
}
243243

244244
// NewProject creates a new Project
245+
// The title will be cut off at 255 characters if it's longer than 255 characters.
245246
func NewProject(ctx context.Context, p *Project) error {
246247
if !IsTemplateTypeValid(p.TemplateType) {
247248
p.TemplateType = TemplateTypeNone
@@ -255,6 +256,8 @@ func NewProject(ctx context.Context, p *Project) error {
255256
return util.NewInvalidArgumentErrorf("project type is not valid")
256257
}
257258

259+
p.Title, _ = util.SplitStringAtByteN(p.Title, 255)
260+
258261
return db.WithTx(ctx, func(ctx context.Context) error {
259262
if err := db.Insert(ctx, p); err != nil {
260263
return err

models/repo/release.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ func IsReleaseExist(ctx context.Context, repoID int64, tagName string) (bool, er
156156

157157
// UpdateRelease updates all columns of a release
158158
func UpdateRelease(ctx context.Context, rel *Release) error {
159+
rel.Title, _ = util.SplitStringAtByteN(rel.Title, 255)
159160
_, err := db.GetEngine(ctx).ID(rel.ID).AllCols().Update(rel)
160161
return err
161162
}

services/release/release.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ func CreateRelease(gitRepo *git.Repository, rel *repo_model.Release, attachmentU
142142
return err
143143
}
144144

145+
rel.Title, _ = util.SplitStringAtByteN(rel.Title, 255)
145146
rel.LowerTagName = strings.ToLower(rel.TagName)
146147
if err = db.Insert(gitRepo.Ctx, rel); err != nil {
147148
return err

0 commit comments

Comments
 (0)