Skip to content

Commit 569c3d1

Browse files
committed
Merge branch 'main' into lunny/repo_dep_org
2 parents 728a642 + c3dedcf commit 569c3d1

File tree

173 files changed

+796
-1053
lines changed

Some content is hidden

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

173 files changed

+796
-1053
lines changed

.github/workflows/pull-db-tests.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,15 @@ jobs:
154154
runs-on: ubuntu-latest
155155
services:
156156
mysql:
157-
image: mysql:8.0
157+
# the bitnami mysql image has more options than the official one, it's easier to customize
158+
image: bitnami/mysql:8.0
158159
env:
159-
MYSQL_ALLOW_EMPTY_PASSWORD: true
160+
ALLOW_EMPTY_PASSWORD: true
160161
MYSQL_DATABASE: testgitea
161162
ports:
162163
- "3306:3306"
164+
options: >-
165+
--mount type=tmpfs,destination=/bitnami/mysql/data
163166
elasticsearch:
164167
image: elasticsearch:7.5.0
165168
env:
@@ -188,7 +191,8 @@ jobs:
188191
- name: run migration tests
189192
run: make test-mysql-migration
190193
- name: run tests
191-
run: make integration-test-coverage
194+
# run: make integration-test-coverage (at the moment, no coverage is really handled)
195+
run: make test-mysql
192196
env:
193197
TAGS: bindata
194198
RACE_ENABLED: true

custom/conf/app.example.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,7 @@ LEVEL = Info
19121912
;ENABLED = true
19131913
;;
19141914
;; Comma-separated list of allowed file extensions (`.zip`), mime types (`text/plain`) or wildcard type (`image/*`, `audio/*`, `video/*`). Empty value or `*/*` allows all types.
1915-
;ALLOWED_TYPES = .csv,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.xls,.xlsx,.zip
1915+
;ALLOWED_TYPES = .avif,.cpuprofile,.csv,.dmp,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.json,.jsonc,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.webp,.xls,.xlsx,.zip
19161916
;;
19171917
;; Max size of each file. Defaults to 2048MB
19181918
;MAX_SIZE = 2048

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/fixtures/repository.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
fork_id: 0
2727
is_template: false
2828
template_id: 0
29-
size: 8478
29+
size: 0
3030
is_fsck_enabled: true
3131
close_issues_via_commit_in_any_branch: false
3232

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/migrations/base/tests.go

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ import (
88
"context"
99
"fmt"
1010
"os"
11-
"path"
1211
"path/filepath"
1312
"runtime"
1413
"testing"
1514

1615
"code.gitea.io/gitea/models/unittest"
1716
"code.gitea.io/gitea/modules/base"
1817
"code.gitea.io/gitea/modules/git"
19-
"code.gitea.io/gitea/modules/log"
2018
"code.gitea.io/gitea/modules/setting"
2119
"code.gitea.io/gitea/modules/testlogger"
2220

@@ -35,27 +33,7 @@ func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (*xorm.Engine, fu
3533
ourSkip := 2
3634
ourSkip += skip
3735
deferFn := testlogger.PrintCurrentTest(t, ourSkip)
38-
assert.NoError(t, os.RemoveAll(setting.RepoRootPath))
39-
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath))
40-
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
41-
if err != nil {
42-
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
43-
}
44-
for _, ownerDir := range ownerDirs {
45-
if !ownerDir.Type().IsDir() {
46-
continue
47-
}
48-
repoDirs, err := os.ReadDir(filepath.Join(setting.RepoRootPath, ownerDir.Name()))
49-
if err != nil {
50-
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
51-
}
52-
for _, repoDir := range repoDirs {
53-
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "pack"), 0o755)
54-
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "info"), 0o755)
55-
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "heads"), 0o755)
56-
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "tag"), 0o755)
57-
}
58-
}
36+
assert.NoError(t, unittest.SyncDirs(filepath.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath))
5937

6038
if err := deleteDB(); err != nil {
6139
t.Errorf("unable to reset database: %v", err)
@@ -112,48 +90,44 @@ func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (*xorm.Engine, fu
11290
}
11391

11492
func MainTest(m *testing.M) {
115-
log.RegisterEventWriter("test", testlogger.NewTestLoggerWriter)
93+
testlogger.Init()
11694

11795
giteaRoot := base.SetupGiteaRoot()
11896
if giteaRoot == "" {
119-
fmt.Println("Environment variable $GITEA_ROOT not set")
120-
os.Exit(1)
97+
testlogger.Fatalf("Environment variable $GITEA_ROOT not set\n")
12198
}
12299
giteaBinary := "gitea"
123100
if runtime.GOOS == "windows" {
124101
giteaBinary += ".exe"
125102
}
126-
setting.AppPath = path.Join(giteaRoot, giteaBinary)
103+
setting.AppPath = filepath.Join(giteaRoot, giteaBinary)
127104
if _, err := os.Stat(setting.AppPath); err != nil {
128-
fmt.Printf("Could not find gitea binary at %s\n", setting.AppPath)
129-
os.Exit(1)
105+
testlogger.Fatalf("Could not find gitea binary at %s\n", setting.AppPath)
130106
}
131107

132108
giteaConf := os.Getenv("GITEA_CONF")
133109
if giteaConf == "" {
134-
giteaConf = path.Join(filepath.Dir(setting.AppPath), "tests/sqlite.ini")
110+
giteaConf = filepath.Join(filepath.Dir(setting.AppPath), "tests/sqlite.ini")
135111
fmt.Printf("Environment variable $GITEA_CONF not set - defaulting to %s\n", giteaConf)
136112
}
137113

138-
if !path.IsAbs(giteaConf) {
139-
setting.CustomConf = path.Join(giteaRoot, giteaConf)
114+
if !filepath.IsAbs(giteaConf) {
115+
setting.CustomConf = filepath.Join(giteaRoot, giteaConf)
140116
} else {
141117
setting.CustomConf = giteaConf
142118
}
143119

144120
tmpDataPath, err := os.MkdirTemp("", "data")
145121
if err != nil {
146-
fmt.Printf("Unable to create temporary data path %v\n", err)
147-
os.Exit(1)
122+
testlogger.Fatalf("Unable to create temporary data path %v\n", err)
148123
}
149124

150125
setting.CustomPath = filepath.Join(setting.AppWorkPath, "custom")
151126
setting.AppDataPath = tmpDataPath
152127

153128
unittest.InitSettings()
154129
if err = git.InitFull(context.Background()); err != nil {
155-
fmt.Printf("Unable to InitFull: %v\n", err)
156-
os.Exit(1)
130+
testlogger.Fatalf("Unable to InitFull: %v\n", err)
157131
}
158132
setting.LoadDBSetting()
159133
setting.InitLoggersForTest()

models/project/project.go

Lines changed: 4 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
@@ -308,6 +311,7 @@ func UpdateProject(ctx context.Context, p *Project) error {
308311
p.CardType = CardTypeTextOnly
309312
}
310313

314+
p.Title, _ = util.SplitStringAtByteN(p.Title, 255)
311315
_, err := db.GetEngine(ctx).ID(p.ID).Cols(
312316
"title",
313317
"description",

0 commit comments

Comments
 (0)