Skip to content

Commit 70405f1

Browse files
authored
Merge branch 'main' into rb/reduce-integration-test-overhead
2 parents c63ee82 + 249e676 commit 70405f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+493
-453
lines changed

models/actions/run.go

Lines changed: 3 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
@@ -399,6 +401,7 @@ func UpdateRun(ctx context.Context, run *ActionRun, cols ...string) error {
399401
if len(cols) > 0 {
400402
sess.Cols(cols...)
401403
}
404+
run.Title, _ = util.SplitStringAtByteN(run.Title, 255)
402405
affected, err := sess.Update(run)
403406
if err != nil {
404407
return err

models/actions/runner.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ func GetRunnerByID(ctx context.Context, id int64) (*ActionRunner, error) {
252252
// UpdateRunner updates runner's information.
253253
func UpdateRunner(ctx context.Context, r *ActionRunner, cols ...string) error {
254254
e := db.GetEngine(ctx)
255+
r.Name, _ = util.SplitStringAtByteN(r.Name, 255)
255256
var err error
256257
if len(cols) == 0 {
257258
_, err = e.ID(r.ID).AllCols().Update(r)
@@ -278,6 +279,7 @@ func CreateRunner(ctx context.Context, t *ActionRunner) error {
278279
// Remove OwnerID to avoid confusion; it's not worth returning an error here.
279280
t.OwnerID = 0
280281
}
282+
t.Name, _ = util.SplitStringAtByteN(t.Name, 255)
281283
return db.Insert(ctx, t)
282284
}
283285

models/actions/schedule.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
repo_model "code.gitea.io/gitea/models/repo"
1313
user_model "code.gitea.io/gitea/models/user"
1414
"code.gitea.io/gitea/modules/timeutil"
15+
"code.gitea.io/gitea/modules/util"
1516
webhook_module "code.gitea.io/gitea/modules/webhook"
1617
)
1718

@@ -67,6 +68,7 @@ func CreateScheduleTask(ctx context.Context, rows []*ActionSchedule) error {
6768

6869
// Loop through each schedule row
6970
for _, row := range rows {
71+
row.Title, _ = util.SplitStringAtByteN(row.Title, 255)
7072
// Create new schedule row
7173
if err = db.Insert(ctx, row); err != nil {
7274
return err

models/activities/action.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ func (a *Action) GetActDisplayNameTitle(ctx context.Context) string {
251251
// GetRepoUserName returns the name of the action repository owner.
252252
func (a *Action) GetRepoUserName(ctx context.Context) string {
253253
a.loadRepo(ctx)
254+
if a.Repo == nil {
255+
return "(non-existing-repo)"
256+
}
254257
return a.Repo.OwnerName
255258
}
256259

@@ -263,6 +266,9 @@ func (a *Action) ShortRepoUserName(ctx context.Context) string {
263266
// GetRepoName returns the name of the action repository.
264267
func (a *Action) GetRepoName(ctx context.Context) string {
265268
a.loadRepo(ctx)
269+
if a.Repo == nil {
270+
return "(non-existing-repo)"
271+
}
266272
return a.Repo.Name
267273
}
268274

models/issues/issue_update.go

Lines changed: 4 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
)
@@ -138,6 +139,7 @@ func ChangeIssueTitle(ctx context.Context, issue *Issue, doer *user_model.User,
138139
}
139140
defer committer.Close()
140141

142+
issue.Title, _ = util.SplitStringAtByteN(issue.Title, 255)
141143
if err = UpdateIssueCols(ctx, issue, "name"); err != nil {
142144
return fmt.Errorf("updateIssueCols: %w", err)
143145
}
@@ -386,6 +388,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue
386388
}
387389

388390
// NewIssue creates new issue with labels for repository.
391+
// The title will be cut off at 255 characters if it's longer than 255 characters.
389392
func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) {
390393
ctx, committer, err := db.TxContext(ctx)
391394
if err != nil {
@@ -399,6 +402,7 @@ func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *Issue, la
399402
}
400403

401404
issue.Index = idx
405+
issue.Title, _ = util.SplitStringAtByteN(issue.Title, 255)
402406

403407
if err = NewIssueWithIndex(ctx, issue.Poster, NewIssueOptions{
404408
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/organization/mini_org.go

Lines changed: 0 additions & 78 deletions
This file was deleted.

models/organization/org.go

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ import (
2525
"xorm.io/xorm"
2626
)
2727

28-
// ________ .__ __ .__
29-
// \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
30-
// / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
31-
// / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
32-
// \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
33-
// \/ /_____/ \/ \/ \/ \/ \/
34-
3528
// ErrOrgNotExist represents a "OrgNotExist" kind of error.
3629
type ErrOrgNotExist struct {
3730
ID int64
@@ -465,42 +458,6 @@ func GetUsersWhoCanCreateOrgRepo(ctx context.Context, orgID int64) (map[int64]*u
465458
And("team_user.org_id = ?", orgID).Find(&users)
466459
}
467460

468-
// SearchOrganizationsOptions options to filter organizations
469-
type SearchOrganizationsOptions struct {
470-
db.ListOptions
471-
All bool
472-
}
473-
474-
// FindOrgOptions finds orgs options
475-
type FindOrgOptions struct {
476-
db.ListOptions
477-
UserID int64
478-
IncludePrivate bool
479-
}
480-
481-
func queryUserOrgIDs(userID int64, includePrivate bool) *builder.Builder {
482-
cond := builder.Eq{"uid": userID}
483-
if !includePrivate {
484-
cond["is_public"] = true
485-
}
486-
return builder.Select("org_id").From("org_user").Where(cond)
487-
}
488-
489-
func (opts FindOrgOptions) ToConds() builder.Cond {
490-
var cond builder.Cond = builder.Eq{"`user`.`type`": user_model.UserTypeOrganization}
491-
if opts.UserID > 0 {
492-
cond = cond.And(builder.In("`user`.`id`", queryUserOrgIDs(opts.UserID, opts.IncludePrivate)))
493-
}
494-
if !opts.IncludePrivate {
495-
cond = cond.And(builder.Eq{"`user`.visibility": structs.VisibleTypePublic})
496-
}
497-
return cond
498-
}
499-
500-
func (opts FindOrgOptions) ToOrders() string {
501-
return "`user`.name ASC"
502-
}
503-
504461
// HasOrgOrUserVisible tells if the given user can see the given org or user
505462
func HasOrgOrUserVisible(ctx context.Context, orgOrUser, user *user_model.User) bool {
506463
// If user is nil, it's an anonymous user/request.
@@ -533,20 +490,6 @@ func HasOrgsVisible(ctx context.Context, orgs []*Organization, user *user_model.
533490
return false
534491
}
535492

536-
// GetOrgsCanCreateRepoByUserID returns a list of organizations where given user ID
537-
// are allowed to create repos.
538-
func GetOrgsCanCreateRepoByUserID(ctx context.Context, userID int64) ([]*Organization, error) {
539-
orgs := make([]*Organization, 0, 10)
540-
541-
return orgs, db.GetEngine(ctx).Where(builder.In("id", builder.Select("`user`.id").From("`user`").
542-
Join("INNER", "`team_user`", "`team_user`.org_id = `user`.id").
543-
Join("INNER", "`team`", "`team`.id = `team_user`.team_id").
544-
Where(builder.Eq{"`team_user`.uid": userID}).
545-
And(builder.Eq{"`team`.authorize": perm.AccessModeOwner}.Or(builder.Eq{"`team`.can_create_org_repo": true})))).
546-
Asc("`user`.name").
547-
Find(&orgs)
548-
}
549-
550493
// GetOrgUsersByOrgID returns all organization-user relations by organization ID.
551494
func GetOrgUsersByOrgID(ctx context.Context, opts *FindOrgMembersOpts) ([]*OrgUser, error) {
552495
sess := db.GetEngine(ctx).Where("org_id=?", opts.OrgID)

0 commit comments

Comments
 (0)