Skip to content

Commit f1b3305

Browse files
authored
Merge branch 'main' into lunny/fix-oauth2-disable
2 parents ff56466 + a928739 commit f1b3305

File tree

299 files changed

+5020
-4403
lines changed

Some content is hidden

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

299 files changed

+5020
-4403
lines changed

custom/conf/app.example.ini

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2642,9 +2642,15 @@ LEVEL = Info
26422642
;; override the azure blob base path if storage type is azureblob
26432643
;AZURE_BLOB_BASE_PATH = lfs/
26442644

2645+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2646+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2647+
;; settings for Gitea's LFS client (eg: mirroring an upstream lfs endpoint)
2648+
;;
26452649
;[lfs_client]
2646-
;; When mirroring an upstream lfs endpoint, limit the number of pointers in each batch request to this number
2650+
;; Limit the number of pointers in each batch request to this number
26472651
;BATCH_SIZE = 20
2652+
;; Limit the number of concurrent upload/download operations within a batch
2653+
;BATCH_OPERATION_CONCURRENCY = 8
26482654

26492655
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26502656
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ require (
124124
golang.org/x/image v0.21.0
125125
golang.org/x/net v0.30.0
126126
golang.org/x/oauth2 v0.23.0
127+
golang.org/x/sync v0.8.0
127128
golang.org/x/sys v0.26.0
128129
golang.org/x/text v0.19.0
129130
golang.org/x/tools v0.26.0
@@ -316,7 +317,6 @@ require (
316317
go.uber.org/zap v1.27.0 // indirect
317318
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
318319
golang.org/x/mod v0.21.0 // indirect
319-
golang.org/x/sync v0.8.0 // indirect
320320
golang.org/x/time v0.7.0 // indirect
321321
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect
322322
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect

models/actions/schedule_spec_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ import (
77
"testing"
88
"time"
99

10+
"code.gitea.io/gitea/modules/test"
11+
1012
"github.com/stretchr/testify/assert"
1113
"github.com/stretchr/testify/require"
1214
)
1315

1416
func TestActionScheduleSpec_Parse(t *testing.T) {
1517
// Mock the local timezone is not UTC
16-
local := time.Local
1718
tz, err := time.LoadLocation("Asia/Shanghai")
1819
require.NoError(t, err)
19-
defer func() {
20-
time.Local = local
21-
}()
22-
time.Local = tz
20+
defer test.MockVariableValue(&time.Local, tz)()
2321

2422
now, err := time.Parse(time.RFC3339, "2024-07-31T15:47:55+08:00")
2523
require.NoError(t, err)

models/activities/action.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ func (a *Action) TableIndices() []*schemas.Index {
171171
cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType)
172172
cudIndex.AddColumn("created_unix", "user_id", "is_deleted")
173173

174-
indices := []*schemas.Index{actUserIndex, repoIndex, cudIndex}
174+
cuIndex := schemas.NewIndex("c_u", schemas.IndexType)
175+
cuIndex.AddColumn("user_id", "is_deleted")
176+
177+
indices := []*schemas.Index{actUserIndex, repoIndex, cudIndex, cuIndex}
175178

176179
return indices
177180
}

models/issues/milestone.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,9 @@ func (m *Milestone) BeforeUpdate() {
8484
// this object.
8585
func (m *Milestone) AfterLoad() {
8686
m.NumOpenIssues = m.NumIssues - m.NumClosedIssues
87-
if m.DeadlineUnix.Year() == 9999 {
87+
if m.DeadlineUnix == 0 {
8888
return
8989
}
90-
9190
m.DeadlineString = m.DeadlineUnix.FormatDate()
9291
if m.IsClosed {
9392
m.IsOverdue = m.ClosedDateUnix >= m.DeadlineUnix

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ func prepareMigrationTasks() []*migration {
364364
newMigration(304, "Add index for release sha1", v1_23.AddIndexForReleaseSha1),
365365
newMigration(305, "Add Repository Licenses", v1_23.AddRepositoryLicenses),
366366
newMigration(306, "Add BlockAdminMergeOverride to ProtectedBranch", v1_23.AddBlockAdminMergeOverrideBranchProtection),
367+
newMigration(307, "Fix milestone deadline_unix when there is no due date", v1_23.FixMilestoneNoDueDate),
368+
newMigration(308, "Add index(user_id, is_deleted) for action table", v1_23.AddNewIndexForUserDashboard),
367369
}
368370
return preparedMigrations
369371
}

models/migrations/v1_23/v307.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_23 //nolint
5+
6+
import (
7+
"code.gitea.io/gitea/modules/timeutil"
8+
9+
"xorm.io/xorm"
10+
)
11+
12+
func FixMilestoneNoDueDate(x *xorm.Engine) error {
13+
type Milestone struct {
14+
DeadlineUnix timeutil.TimeStamp
15+
}
16+
// Wednesday, December 1, 9999 12:00:00 AM GMT+00:00
17+
_, err := x.Table("milestone").Where("deadline_unix > 253399622400").
18+
Cols("deadline_unix").
19+
Update(&Milestone{DeadlineUnix: 0})
20+
return err
21+
}

models/migrations/v1_23/v308.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_23 //nolint
5+
6+
import (
7+
"code.gitea.io/gitea/modules/timeutil"
8+
9+
"xorm.io/xorm"
10+
"xorm.io/xorm/schemas"
11+
)
12+
13+
type improveActionTableIndicesAction struct {
14+
ID int64 `xorm:"pk autoincr"`
15+
UserID int64 `xorm:"INDEX"` // Receiver user id.
16+
OpType int
17+
ActUserID int64 // Action user id.
18+
RepoID int64
19+
CommentID int64 `xorm:"INDEX"`
20+
IsDeleted bool `xorm:"NOT NULL DEFAULT false"`
21+
RefName string
22+
IsPrivate bool `xorm:"NOT NULL DEFAULT false"`
23+
Content string `xorm:"TEXT"`
24+
CreatedUnix timeutil.TimeStamp `xorm:"created"`
25+
}
26+
27+
// TableName sets the name of this table
28+
func (*improveActionTableIndicesAction) TableName() string {
29+
return "action"
30+
}
31+
32+
func (a *improveActionTableIndicesAction) TableIndices() []*schemas.Index {
33+
repoIndex := schemas.NewIndex("r_u_d", schemas.IndexType)
34+
repoIndex.AddColumn("repo_id", "user_id", "is_deleted")
35+
36+
actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
37+
actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
38+
39+
cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType)
40+
cudIndex.AddColumn("created_unix", "user_id", "is_deleted")
41+
42+
cuIndex := schemas.NewIndex("c_u", schemas.IndexType)
43+
cuIndex.AddColumn("user_id", "is_deleted")
44+
45+
indices := []*schemas.Index{actUserIndex, repoIndex, cudIndex, cuIndex}
46+
47+
return indices
48+
}
49+
50+
func AddNewIndexForUserDashboard(x *xorm.Engine) error {
51+
return x.Sync(new(improveActionTableIndicesAction))
52+
}

models/perm/access_mode.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,6 @@ func ParseAccessMode(permission string, allowed ...AccessMode) AccessMode {
6060
}
6161
return util.Iif(slices.Contains(allowed, m), m, AccessModeNone)
6262
}
63+
64+
// ErrInvalidAccessMode is returned when an invalid access mode is used
65+
var ErrInvalidAccessMode = util.NewInvalidArgumentErrorf("Invalid access mode")

models/repo/user_repo.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,26 +110,28 @@ func GetRepoAssignees(ctx context.Context, repo *Repository) (_ []*user_model.Us
110110
return nil, err
111111
}
112112

113-
additionalUserIDs := make([]int64, 0, 10)
114-
if err = e.Table("team_user").
115-
Join("INNER", "team_repo", "`team_repo`.team_id = `team_user`.team_id").
116-
Join("INNER", "team_unit", "`team_unit`.team_id = `team_user`.team_id").
117-
Where("`team_repo`.repo_id = ? AND (`team_unit`.access_mode >= ? OR (`team_unit`.access_mode = ? AND `team_unit`.`type` = ?))",
118-
repo.ID, perm.AccessModeWrite, perm.AccessModeRead, unit.TypePullRequests).
119-
Distinct("`team_user`.uid").
120-
Select("`team_user`.uid").
121-
Find(&additionalUserIDs); err != nil {
122-
return nil, err
123-
}
124-
125113
uniqueUserIDs := make(container.Set[int64])
126114
uniqueUserIDs.AddMultiple(userIDs...)
127-
uniqueUserIDs.AddMultiple(additionalUserIDs...)
115+
116+
if repo.Owner.IsOrganization() {
117+
additionalUserIDs := make([]int64, 0, 10)
118+
if err = e.Table("team_user").
119+
Join("INNER", "team_repo", "`team_repo`.team_id = `team_user`.team_id").
120+
Join("INNER", "team_unit", "`team_unit`.team_id = `team_user`.team_id").
121+
Where("`team_repo`.repo_id = ? AND (`team_unit`.access_mode >= ? OR (`team_unit`.access_mode = ? AND `team_unit`.`type` = ?))",
122+
repo.ID, perm.AccessModeWrite, perm.AccessModeRead, unit.TypePullRequests).
123+
Distinct("`team_user`.uid").
124+
Select("`team_user`.uid").
125+
Find(&additionalUserIDs); err != nil {
126+
return nil, err
127+
}
128+
uniqueUserIDs.AddMultiple(additionalUserIDs...)
129+
}
128130

129131
// Leave a seat for owner itself to append later, but if owner is an organization
130132
// and just waste 1 unit is cheaper than re-allocate memory once.
131133
users := make([]*user_model.User, 0, len(uniqueUserIDs)+1)
132-
if len(userIDs) > 0 {
134+
if len(uniqueUserIDs) > 0 {
133135
if err = e.In("id", uniqueUserIDs.Values()).
134136
Where(builder.Eq{"`user`.is_active": true}).
135137
OrderBy(user_model.GetOrderByName()).

0 commit comments

Comments
 (0)