Skip to content

Commit 00158fd

Browse files
authored
Merge branch 'main' into rb/disable-gravatar-in-tests
2 parents bef5f30 + efb55cd commit 00158fd

File tree

118 files changed

+1964
-1414
lines changed

Some content is hidden

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

118 files changed

+1964
-1414
lines changed

flake.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
poetry
3030

3131
# backend
32-
go_1_22
3332
gofumpt
3433
sqlite
3534
];

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/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

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)