Skip to content

Commit 198a1a5

Browse files
authored
Merge branch 'main' into lunny/respsect_org_fullname
2 parents 422a6bd + 8a20fba commit 198a1a5

File tree

194 files changed

+1526
-1583
lines changed

Some content is hidden

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

194 files changed

+1526
-1583
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/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/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

models/repo/repo_list.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,14 @@ func (repos RepositoryList) IDs() []int64 {
9898
return repoIDs
9999
}
100100

101-
// LoadAttributes loads the attributes for the given RepositoryList
102-
func (repos RepositoryList) LoadAttributes(ctx context.Context) error {
101+
func (repos RepositoryList) LoadOwners(ctx context.Context) error {
103102
if len(repos) == 0 {
104103
return nil
105104
}
106105

107106
userIDs := container.FilterSlice(repos, func(repo *Repository) (int64, bool) {
108107
return repo.OwnerID, true
109108
})
110-
repoIDs := make([]int64, len(repos))
111-
for i := range repos {
112-
repoIDs[i] = repos[i].ID
113-
}
114109

115110
// Load owners.
116111
users := make(map[int64]*user_model.User, len(userIDs))
@@ -123,12 +118,19 @@ func (repos RepositoryList) LoadAttributes(ctx context.Context) error {
123118
for i := range repos {
124119
repos[i].Owner = users[repos[i].OwnerID]
125120
}
121+
return nil
122+
}
123+
124+
func (repos RepositoryList) LoadLanguageStats(ctx context.Context) error {
125+
if len(repos) == 0 {
126+
return nil
127+
}
126128

127129
// Load primary language.
128130
stats := make(LanguageStatList, 0, len(repos))
129131
if err := db.GetEngine(ctx).
130132
Where("`is_primary` = ? AND `language` != ?", true, "other").
131-
In("`repo_id`", repoIDs).
133+
In("`repo_id`", repos.IDs()).
132134
Find(&stats); err != nil {
133135
return fmt.Errorf("find primary languages: %w", err)
134136
}
@@ -141,10 +143,18 @@ func (repos RepositoryList) LoadAttributes(ctx context.Context) error {
141143
}
142144
}
143145
}
144-
145146
return nil
146147
}
147148

149+
// LoadAttributes loads the attributes for the given RepositoryList
150+
func (repos RepositoryList) LoadAttributes(ctx context.Context) error {
151+
if err := repos.LoadOwners(ctx); err != nil {
152+
return err
153+
}
154+
155+
return repos.LoadLanguageStats(ctx)
156+
}
157+
148158
// SearchRepoOptions holds the search options
149159
type SearchRepoOptions struct {
150160
db.ListOptions

0 commit comments

Comments
 (0)