Skip to content

Commit 2e0f92d

Browse files
authored
Merge branch 'release/v1.22' into lunny/release_note_1.22.4
2 parents 5b8cd0c + cf1a38b commit 2e0f92d

Some content is hidden

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

68 files changed

+1301
-454
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
@@ -386,6 +388,7 @@ func UpdateRun(ctx context.Context, run *ActionRun, cols ...string) error {
386388
if len(cols) > 0 {
387389
sess.Cols(cols...)
388390
}
391+
run.Title, _ = util.SplitStringAtByteN(run.Title, 255)
389392
affected, err := sess.Update(run)
390393
if err != nil {
391394
return err

models/actions/runner.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ func GetRunnerByID(ctx context.Context, id int64) (*ActionRunner, error) {
242242
// UpdateRunner updates runner's information.
243243
func UpdateRunner(ctx context.Context, r *ActionRunner, cols ...string) error {
244244
e := db.GetEngine(ctx)
245+
r.Name, _ = util.SplitStringAtByteN(r.Name, 255)
245246
var err error
246247
if len(cols) == 0 {
247248
_, err = e.ID(r.ID).AllCols().Update(r)
@@ -263,6 +264,7 @@ func DeleteRunner(ctx context.Context, id int64) error {
263264

264265
// CreateRunner creates new runner.
265266
func CreateRunner(ctx context.Context, t *ActionRunner) error {
267+
t.Name, _ = util.SplitStringAtByteN(t.Name, 255)
266268
return db.Insert(ctx, t)
267269
}
268270

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
"github.com/robfig/cron/v3"
@@ -71,6 +72,7 @@ func CreateScheduleTask(ctx context.Context, rows []*ActionSchedule) error {
7172

7273
// Loop through each schedule row
7374
for _, row := range rows {
75+
row.Title, _ = util.SplitStringAtByteN(row.Title, 255)
7476
// Create new schedule row
7577
if err = db.Insert(ctx, row); err != nil {
7678
return err

models/db/collation.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ func CheckCollations(x *xorm.Engine) (*CheckCollationsResult, error) {
6868

6969
var candidateCollations []string
7070
if x.Dialect().URI().DBType == schemas.MYSQL {
71-
if _, err = x.SQL("SELECT @@collation_database").Get(&res.DatabaseCollation); err != nil {
71+
_, err = x.SQL("SELECT DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ?", setting.Database.Name).Get(&res.DatabaseCollation)
72+
if err != nil {
7273
return nil, err
7374
}
7475
res.IsCollationCaseSensitive = func(s string) bool {

models/fixtures/action_task.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
-
2+
id: 46
3+
attempt: 3
4+
runner_id: 1
5+
status: 3 # 3 is the status code for "cancelled"
6+
started: 1683636528
7+
stopped: 1683636626
8+
repo_id: 4
9+
owner_id: 1
10+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
11+
is_fork_pull_request: 0
12+
token_hash: 6d8ef48297195edcc8e22c70b3020eaa06c52976db67d39b4260c64a69a2cc1508825121b7b8394e48e00b1bf8718b2aaaaa
13+
token_salt: eeeeeeee
14+
token_last_eight: eeeeeeee
15+
log_filename: artifact-test2/2f/47.log
16+
log_in_storage: 1
17+
log_length: 707
18+
log_size: 90179
19+
log_expired: 0
120
-
221
id: 47
322
job_id: 192

models/fixtures/user.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@
332332
repo_admin_change_team_access: false
333333
theme: ""
334334
keep_activity_private: false
335+
created_unix: 1730468968
335336

336337
-
337338
id: 10

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
}
@@ -381,6 +383,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue
381383
}
382384

383385
// NewIssue creates new issue with labels for repository.
386+
// The title will be cut off at 255 characters if it's longer than 255 characters.
384387
func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) {
385388
ctx, committer, err := db.TxContext(ctx)
386389
if err != nil {
@@ -394,6 +397,7 @@ func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *Issue, la
394397
}
395398

396399
issue.Index = idx
400+
issue.Title, _ = util.SplitStringAtByteN(issue.Title, 255)
397401

398402
if err = NewIssueWithIndex(ctx, issue.Poster, NewIssueOptions{
399403
Repo: repo,

models/issues/pull.go

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

547547
issue.Index = idx
548+
issue.Title, _ = util.SplitStringAtByteN(issue.Title, 255)
548549

549550
if err = NewIssueWithIndex(ctx, issue.Poster, NewIssueOptions{
550551
Repo: repo,

models/organization/team_repo.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"code.gitea.io/gitea/models/db"
1010
"code.gitea.io/gitea/models/perm"
1111
repo_model "code.gitea.io/gitea/models/repo"
12+
"code.gitea.io/gitea/models/unit"
1213

1314
"xorm.io/builder"
1415
)
@@ -83,3 +84,16 @@ func GetTeamsWithAccessToRepo(ctx context.Context, orgID, repoID int64, mode per
8384
OrderBy("name").
8485
Find(&teams)
8586
}
87+
88+
// GetTeamsWithAccessToRepoUnit returns all teams in an organization that have given access level to the repository special unit.
89+
func GetTeamsWithAccessToRepoUnit(ctx context.Context, orgID, repoID int64, mode perm.AccessMode, unitType unit.Type) ([]*Team, error) {
90+
teams := make([]*Team, 0, 5)
91+
return teams, db.GetEngine(ctx).Where("team_unit.access_mode >= ?", mode).
92+
Join("INNER", "team_repo", "team_repo.team_id = team.id").
93+
Join("INNER", "team_unit", "team_unit.team_id = team.id").
94+
And("team_repo.org_id = ?", orgID).
95+
And("team_repo.repo_id = ?", repoID).
96+
And("team_unit.type = ?", unitType).
97+
OrderBy("name").
98+
Find(&teams)
99+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package organization_test
5+
6+
import (
7+
"testing"
8+
9+
"code.gitea.io/gitea/models/db"
10+
"code.gitea.io/gitea/models/organization"
11+
"code.gitea.io/gitea/models/perm"
12+
"code.gitea.io/gitea/models/repo"
13+
"code.gitea.io/gitea/models/unit"
14+
"code.gitea.io/gitea/models/unittest"
15+
16+
"github.com/stretchr/testify/assert"
17+
)
18+
19+
func TestGetTeamsWithAccessToRepoUnit(t *testing.T) {
20+
assert.NoError(t, unittest.PrepareTestDatabase())
21+
22+
org41 := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 41})
23+
repo61 := unittest.AssertExistsAndLoadBean(t, &repo.Repository{ID: 61})
24+
25+
teams, err := organization.GetTeamsWithAccessToRepoUnit(db.DefaultContext, org41.ID, repo61.ID, perm.AccessModeRead, unit.TypePullRequests)
26+
assert.NoError(t, err)
27+
if assert.Len(t, teams, 2) {
28+
assert.EqualValues(t, 21, teams[0].ID)
29+
assert.EqualValues(t, 22, teams[1].ID)
30+
}
31+
}

0 commit comments

Comments
 (0)