Skip to content

Commit f5a83a7

Browse files
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-show
2 parents b387e41 + 896314c commit f5a83a7

File tree

215 files changed

+1698
-1718
lines changed

Some content is hidden

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

215 files changed

+1698
-1718
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/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/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/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/repo/fork.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,6 @@ func GetUserFork(ctx context.Context, repoID, userID int64) (*Repository, error)
5454
return &forkedRepo, nil
5555
}
5656

57-
// GetForks returns all the forks of the repository
58-
func GetForks(ctx context.Context, repo *Repository, listOptions db.ListOptions) ([]*Repository, error) {
59-
sess := db.GetEngine(ctx)
60-
61-
var forks []*Repository
62-
if listOptions.Page == 0 {
63-
forks = make([]*Repository, 0, repo.NumForks)
64-
} else {
65-
forks = make([]*Repository, 0, listOptions.PageSize)
66-
sess = db.SetSessionPagination(sess, &listOptions)
67-
}
68-
69-
return forks, sess.Find(&forks, &Repository{ForkID: repo.ID})
70-
}
71-
7257
// IncrementRepoForkNum increment repository fork number
7358
func IncrementRepoForkNum(ctx context.Context, repoID int64) error {
7459
_, err := db.GetEngine(ctx).Exec("UPDATE `repository` SET num_forks=num_forks+1 WHERE id=?", repoID)

models/repo/pushmirror.go

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ import (
99

1010
"code.gitea.io/gitea/models/db"
1111
"code.gitea.io/gitea/modules/log"
12+
"code.gitea.io/gitea/modules/optional"
1213
"code.gitea.io/gitea/modules/timeutil"
1314
"code.gitea.io/gitea/modules/util"
1415

1516
"xorm.io/builder"
1617
)
1718

18-
// ErrPushMirrorNotExist mirror does not exist error
19-
var ErrPushMirrorNotExist = util.NewNotExistErrorf("PushMirror does not exist")
20-
2119
// PushMirror represents mirror information of a repository.
2220
type PushMirror struct {
2321
ID int64 `xorm:"pk autoincr"`
@@ -96,26 +94,46 @@ func DeletePushMirrors(ctx context.Context, opts PushMirrorOptions) error {
9694
return util.NewInvalidArgumentErrorf("repoID required and must be set")
9795
}
9896

97+
type findPushMirrorOptions struct {
98+
db.ListOptions
99+
RepoID int64
100+
SyncOnCommit optional.Option[bool]
101+
}
102+
103+
func (opts findPushMirrorOptions) ToConds() builder.Cond {
104+
cond := builder.NewCond()
105+
if opts.RepoID > 0 {
106+
cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
107+
}
108+
if opts.SyncOnCommit.Has() {
109+
cond = cond.And(builder.Eq{"sync_on_commit": opts.SyncOnCommit.Value()})
110+
}
111+
return cond
112+
}
113+
99114
// GetPushMirrorsByRepoID returns push-mirror information of a repository.
100115
func GetPushMirrorsByRepoID(ctx context.Context, repoID int64, listOptions db.ListOptions) ([]*PushMirror, int64, error) {
101-
sess := db.GetEngine(ctx).Where("repo_id = ?", repoID)
102-
if listOptions.Page != 0 {
103-
sess = db.SetSessionPagination(sess, &listOptions)
104-
mirrors := make([]*PushMirror, 0, listOptions.PageSize)
105-
count, err := sess.FindAndCount(&mirrors)
106-
return mirrors, count, err
116+
return db.FindAndCount[PushMirror](ctx, findPushMirrorOptions{
117+
ListOptions: listOptions,
118+
RepoID: repoID,
119+
})
120+
}
121+
122+
func GetPushMirrorByIDAndRepoID(ctx context.Context, id, repoID int64) (*PushMirror, bool, error) {
123+
var pushMirror PushMirror
124+
has, err := db.GetEngine(ctx).Where("id = ?", id).And("repo_id = ?", repoID).Get(&pushMirror)
125+
if !has || err != nil {
126+
return nil, has, err
107127
}
108-
mirrors := make([]*PushMirror, 0, 10)
109-
count, err := sess.FindAndCount(&mirrors)
110-
return mirrors, count, err
128+
return &pushMirror, true, nil
111129
}
112130

113131
// GetPushMirrorsSyncedOnCommit returns push-mirrors for this repo that should be updated by new commits
114132
func GetPushMirrorsSyncedOnCommit(ctx context.Context, repoID int64) ([]*PushMirror, error) {
115-
mirrors := make([]*PushMirror, 0, 10)
116-
return mirrors, db.GetEngine(ctx).
117-
Where("repo_id = ? AND sync_on_commit = ?", repoID, true).
118-
Find(&mirrors)
133+
return db.Find[PushMirror](ctx, findPushMirrorOptions{
134+
RepoID: repoID,
135+
SyncOnCommit: optional.Some(true),
136+
})
119137
}
120138

121139
// PushMirrorsIterate iterates all push-mirror repositories.

models/repo/repo.go

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"fmt"
99
"html/template"
10+
"maps"
1011
"net"
1112
"net/url"
1213
"path/filepath"
@@ -165,10 +166,10 @@ type Repository struct {
165166

166167
Status RepositoryStatus `xorm:"NOT NULL DEFAULT 0"`
167168

168-
RenderingMetas map[string]string `xorm:"-"`
169-
DocumentRenderingMetas map[string]string `xorm:"-"`
170-
Units []*RepoUnit `xorm:"-"`
171-
PrimaryLanguage *LanguageStat `xorm:"-"`
169+
commonRenderingMetas map[string]string `xorm:"-"`
170+
171+
Units []*RepoUnit `xorm:"-"`
172+
PrimaryLanguage *LanguageStat `xorm:"-"`
172173

173174
IsFork bool `xorm:"INDEX NOT NULL DEFAULT false"`
174175
ForkID int64 `xorm:"INDEX"`
@@ -473,9 +474,8 @@ func (repo *Repository) MustOwner(ctx context.Context) *user_model.User {
473474
return repo.Owner
474475
}
475476

476-
// ComposeMetas composes a map of metas for properly rendering issue links and external issue trackers.
477-
func (repo *Repository) ComposeMetas(ctx context.Context) map[string]string {
478-
if len(repo.RenderingMetas) == 0 {
477+
func (repo *Repository) composeCommonMetas(ctx context.Context) map[string]string {
478+
if len(repo.commonRenderingMetas) == 0 {
479479
metas := map[string]string{
480480
"user": repo.OwnerName,
481481
"repo": repo.Name,
@@ -508,21 +508,34 @@ func (repo *Repository) ComposeMetas(ctx context.Context) map[string]string {
508508
metas["org"] = strings.ToLower(repo.OwnerName)
509509
}
510510

511-
repo.RenderingMetas = metas
511+
repo.commonRenderingMetas = metas
512512
}
513-
return repo.RenderingMetas
513+
return repo.commonRenderingMetas
514+
}
515+
516+
// ComposeMetas composes a map of metas for properly rendering comments or comment-like contents (commit message)
517+
func (repo *Repository) ComposeMetas(ctx context.Context) map[string]string {
518+
metas := maps.Clone(repo.composeCommonMetas(ctx))
519+
metas["markdownLineBreakStyle"] = "comment"
520+
metas["markupAllowShortIssuePattern"] = "true"
521+
return metas
514522
}
515523

516-
// ComposeDocumentMetas composes a map of metas for properly rendering documents
524+
// ComposeWikiMetas composes a map of metas for properly rendering wikis
525+
func (repo *Repository) ComposeWikiMetas(ctx context.Context) map[string]string {
526+
// does wiki need the "teams" and "org" from common metas?
527+
metas := maps.Clone(repo.composeCommonMetas(ctx))
528+
metas["markdownLineBreakStyle"] = "document"
529+
metas["markupAllowShortIssuePattern"] = "true"
530+
return metas
531+
}
532+
533+
// ComposeDocumentMetas composes a map of metas for properly rendering documents (repo files)
517534
func (repo *Repository) ComposeDocumentMetas(ctx context.Context) map[string]string {
518-
if len(repo.DocumentRenderingMetas) == 0 {
519-
metas := map[string]string{}
520-
for k, v := range repo.ComposeMetas(ctx) {
521-
metas[k] = v
522-
}
523-
repo.DocumentRenderingMetas = metas
524-
}
525-
return repo.DocumentRenderingMetas
535+
// does document(file) need the "teams" and "org" from common metas?
536+
metas := maps.Clone(repo.composeCommonMetas(ctx))
537+
metas["markdownLineBreakStyle"] = "document"
538+
return metas
526539
}
527540

528541
// GetBaseRepo populates repo.BaseRepo for a fork repository and

0 commit comments

Comments
 (0)