Skip to content

Commit 36e25fa

Browse files
committed
Merge branch 'main' into full-gc-lfs
2 parents 2d36bf7 + 0e46499 commit 36e25fa

File tree

229 files changed

+932
-903
lines changed

Some content is hidden

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

229 files changed

+932
-903
lines changed

.drone.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ steps:
600600
from_secret: crowdin_key
601601

602602
- name: update
603-
image: alpine:3.13
603+
image: alpine:3.17
604604
pull: always
605605
commands:
606606
- ./build/update-locales.sh

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Build stage
2-
FROM golang:1.19-alpine3.16 AS build-env
2+
FROM golang:1.19-alpine3.17 AS build-env
33

44
ARG GOPROXY
55
ENV GOPROXY ${GOPROXY:-direct}
@@ -23,7 +23,7 @@ RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
2323
# Begin env-to-ini build
2424
RUN go build contrib/environment-to-ini/environment-to-ini.go
2525

26-
FROM alpine:3.16
26+
FROM alpine:3.17
2727
LABEL maintainer="[email protected]"
2828

2929
EXPOSE 22 3000

Dockerfile.rootless

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Build stage
2-
FROM golang:1.19-alpine3.16 AS build-env
2+
FROM golang:1.19-alpine3.17 AS build-env
33

44
ARG GOPROXY
55
ENV GOPROXY ${GOPROXY:-direct}
@@ -23,7 +23,7 @@ RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
2323
# Begin env-to-ini build
2424
RUN go build contrib/environment-to-ini/environment-to-ini.go
2525

26-
FROM alpine:3.16
26+
FROM alpine:3.17
2727
LABEL maintainer="[email protected]"
2828

2929
EXPOSE 2222 3000

cmd/admin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ func runDeleteUser(c *cli.Context) error {
665665
} else if c.IsSet("username") {
666666
user, err = user_model.GetUserByName(ctx, c.String("username"))
667667
} else {
668-
user, err = user_model.GetUserByID(c.Int64("id"))
668+
user, err = user_model.GetUserByID(ctx, c.Int64("id"))
669669
}
670670
if err != nil {
671671
return err

docs/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ params:
2323
goVersion: 1.19
2424
minNodeVersion: 14
2525
search: nav
26+
repo: "https://github.com/go-gitea/gitea"
27+
docContentPath: "docs/content"
2628

2729
outputs:
2830
home:

docs/content/doc/packages/overview.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The following package managers are currently supported:
3232
| [Generic]({{< relref "doc/packages/generic.en-us.md" >}}) | - | any HTTP client |
3333
| [Helm]({{< relref "doc/packages/helm.en-us.md" >}}) | - | any HTTP client, `cm-push` |
3434
| [Maven]({{< relref "doc/packages/maven.en-us.md" >}}) | Java | `mvn`, `gradle` |
35-
| [npm]({{< relref "doc/packages/npm.en-us.md" >}}) | JavaScript | `npm`, `yarn` |
35+
| [npm]({{< relref "doc/packages/npm.en-us.md" >}}) | JavaScript | `npm`, `yarn`, `pnpm` |
3636
| [NuGet]({{< relref "doc/packages/nuget.en-us.md" >}}) | .NET | `nuget` |
3737
| [Pub]({{< relref "doc/packages/pub.en-us.md" >}}) | Dart | `dart`, `flutter` |
3838
| [PyPI]({{< relref "doc/packages/pypi.en-us.md" >}}) | Python | `pip`, `twine` |

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module code.gitea.io/gitea
33
go 1.18
44

55
require (
6-
code.gitea.io/gitea-vet v0.2.2-0.20220122151748-48ebc902541b
6+
code.gitea.io/gitea-vet v0.2.2
77
code.gitea.io/sdk/gitea v0.15.1
88
codeberg.org/gusted/mcaptcha v0.0.0-20220723083913-4f3072e1d570
99
gitea.com/go-chi/binding v0.0.0-20221013104517-b29891619681
@@ -15,7 +15,7 @@ require (
1515
github.com/42wim/sshsig v0.0.0-20211121163825-841cf5bbc121
1616
github.com/NYTimes/gziphandler v1.1.1
1717
github.com/PuerkitoBio/goquery v1.8.0
18-
github.com/alecthomas/chroma/v2 v2.3.0
18+
github.com/alecthomas/chroma/v2 v2.4.0
1919
github.com/blevesearch/bleve/v2 v2.3.4
2020
github.com/buildkite/terminal-to-html/v3 v3.7.0
2121
github.com/caddyserver/certmagic v0.17.2

go.sum

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
6565
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
6666
cloud.google.com/go/storage v1.22.1/go.mod h1:S8N1cAStu7BOeFfE8KAQzmyyLkK8p/vmRq6kuBTW58Y=
6767
code.gitea.io/gitea-vet v0.2.1/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFjGGfE=
68-
code.gitea.io/gitea-vet v0.2.2-0.20220122151748-48ebc902541b h1:uv9a8eGSdQ8Dr4HyUcuHFfDsk/QuwO+wf+Y99RYdxY0=
69-
code.gitea.io/gitea-vet v0.2.2-0.20220122151748-48ebc902541b/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFjGGfE=
68+
code.gitea.io/gitea-vet v0.2.2 h1:TEOV/Glf38iGmKzKP0EB++Z5OSL4zGg3RrAvlwaMuvk=
69+
code.gitea.io/gitea-vet v0.2.2/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFjGGfE=
7070
code.gitea.io/sdk/gitea v0.11.3/go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY=
7171
code.gitea.io/sdk/gitea v0.15.1 h1:WJreC7YYuxbn0UDaPuWIe/mtiNKTvLN8MLkaw71yx/M=
7272
code.gitea.io/sdk/gitea v0.15.1/go.mod h1:klY2LVI3s3NChzIk/MzMn7G1FHrfU7qd63iSMVoHRBA=
@@ -160,9 +160,10 @@ github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ
160160
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
161161
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
162162
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
163+
github.com/alecthomas/assert/v2 v2.2.0 h1:f6L/b7KE2bfA+9O4FL3CM/xJccDEwPVYd5fALBiuwvw=
163164
github.com/alecthomas/chroma/v2 v2.2.0/go.mod h1:vf4zrexSH54oEjJ7EdB65tGNHmH3pGZmVkgTP5RHvAs=
164-
github.com/alecthomas/chroma/v2 v2.3.0 h1:83xfxrnjv8eK+Cf8qZDzNo3PPF9IbTWHs7z28GY6D0U=
165-
github.com/alecthomas/chroma/v2 v2.3.0/go.mod h1:mZxeWZlxP2Dy+/8cBob2PYd8O2DwNAzave5AY7A2eQw=
165+
github.com/alecthomas/chroma/v2 v2.4.0 h1:Loe2ZjT5x3q1bcWwemqyqEi8p11/IV/ncFCeLYDpWC4=
166+
github.com/alecthomas/chroma/v2 v2.4.0/go.mod h1:6kHzqF5O6FUSJzBXW7fXELjb+e+7OXW4UpoPqMO7IBQ=
166167
github.com/alecthomas/kingpin v2.2.6+incompatible/go.mod h1:59OFYbFVLKQKq+mqrL6Rw5bR0c3ACQaawgXx0QYndlE=
167168
github.com/alecthomas/repr v0.0.0-20220113201626-b1b626ac65ae/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
168169
github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE=
@@ -830,6 +831,7 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO
830831
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
831832
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
832833
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
834+
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
833835
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
834836
github.com/huandu/xstrings v1.0.0/go.mod h1:4qWG/gcEcfX4z/mBDHJ++3ReCw9ibxbsNJbcucJdbSo=
835837
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=

models/activities/action.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ func (a *Action) GetOpType() ActionType {
114114
}
115115

116116
// LoadActUser loads a.ActUser
117-
func (a *Action) LoadActUser() {
117+
func (a *Action) LoadActUser(ctx context.Context) {
118118
if a.ActUser != nil {
119119
return
120120
}
121121
var err error
122-
a.ActUser, err = user_model.GetUserByID(a.ActUserID)
122+
a.ActUser, err = user_model.GetUserByID(ctx, a.ActUserID)
123123
if err == nil {
124124
return
125125
} else if user_model.IsErrUserNotExist(err) {
@@ -129,26 +129,26 @@ func (a *Action) LoadActUser() {
129129
}
130130
}
131131

132-
func (a *Action) loadRepo() {
132+
func (a *Action) loadRepo(ctx context.Context) {
133133
if a.Repo != nil {
134134
return
135135
}
136136
var err error
137-
a.Repo, err = repo_model.GetRepositoryByID(a.RepoID)
137+
a.Repo, err = repo_model.GetRepositoryByID(ctx, a.RepoID)
138138
if err != nil {
139139
log.Error("repo_model.GetRepositoryByID(%d): %v", a.RepoID, err)
140140
}
141141
}
142142

143143
// GetActFullName gets the action's user full name.
144144
func (a *Action) GetActFullName() string {
145-
a.LoadActUser()
145+
a.LoadActUser(db.DefaultContext)
146146
return a.ActUser.FullName
147147
}
148148

149149
// GetActUserName gets the action's user name.
150150
func (a *Action) GetActUserName() string {
151-
a.LoadActUser()
151+
a.LoadActUser(db.DefaultContext)
152152
return a.ActUser.Name
153153
}
154154

@@ -179,7 +179,7 @@ func (a *Action) GetDisplayNameTitle() string {
179179

180180
// GetRepoUserName returns the name of the action repository owner.
181181
func (a *Action) GetRepoUserName() string {
182-
a.loadRepo()
182+
a.loadRepo(db.DefaultContext)
183183
return a.Repo.OwnerName
184184
}
185185

@@ -191,7 +191,7 @@ func (a *Action) ShortRepoUserName() string {
191191

192192
// GetRepoName returns the name of the action repository.
193193
func (a *Action) GetRepoName() string {
194-
a.loadRepo()
194+
a.loadRepo(db.DefaultContext)
195195
return a.Repo.Name
196196
}
197197

@@ -379,7 +379,7 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
379379
cond := builder.NewCond()
380380

381381
if opts.RequestedTeam != nil && opts.RequestedUser == nil {
382-
org, err := user_model.GetUserByID(opts.RequestedTeam.OrgID)
382+
org, err := user_model.GetUserByID(db.DefaultContext, opts.RequestedTeam.OrgID)
383383
if err != nil {
384384
return nil, err
385385
}
@@ -489,7 +489,7 @@ func NotifyWatchers(ctx context.Context, actions ...*Action) error {
489489
}
490490

491491
if repoChanged {
492-
act.loadRepo()
492+
act.loadRepo(ctx)
493493
repo = act.Repo
494494

495495
// check repo owner exist.
@@ -514,7 +514,7 @@ func NotifyWatchers(ctx context.Context, actions ...*Action) error {
514514
permIssue = make([]bool, len(watchers))
515515
permPR = make([]bool, len(watchers))
516516
for i, watcher := range watchers {
517-
user, err := user_model.GetUserByIDCtx(ctx, watcher.UserID)
517+
user, err := user_model.GetUserByID(ctx, watcher.UserID)
518518
if err != nil {
519519
permCode[i] = false
520520
permIssue[i] = false

models/activities/action_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (actions ActionList) loadRepoOwner(ctx context.Context, userMap map[int64]*
8181
}
8282
repoOwner, ok := userMap[action.Repo.OwnerID]
8383
if !ok {
84-
repoOwner, err = user_model.GetUserByIDCtx(ctx, action.Repo.OwnerID)
84+
repoOwner, err = user_model.GetUserByID(ctx, action.Repo.OwnerID)
8585
if err != nil {
8686
if user_model.IsErrUserNotExist(err) {
8787
continue

models/activities/notification.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func createOrUpdateIssueNotifications(ctx context.Context, issueID, commentID, n
245245
// notify
246246
for userID := range toNotify {
247247
issue.Repo.Units = nil
248-
user, err := user_model.GetUserByIDCtx(ctx, userID)
248+
user, err := user_model.GetUserByID(ctx, userID)
249249
if err != nil {
250250
if user_model.IsErrUserNotExist(err) {
251251
continue
@@ -388,7 +388,7 @@ func (n *Notification) LoadAttributes(ctx context.Context) (err error) {
388388

389389
func (n *Notification) loadRepo(ctx context.Context) (err error) {
390390
if n.Repository == nil {
391-
n.Repository, err = repo_model.GetRepositoryByIDCtx(ctx, n.RepoID)
391+
n.Repository, err = repo_model.GetRepositoryByID(ctx, n.RepoID)
392392
if err != nil {
393393
return fmt.Errorf("getRepositoryByID [%d]: %w", n.RepoID, err)
394394
}
@@ -425,7 +425,7 @@ func (n *Notification) loadComment(ctx context.Context) (err error) {
425425

426426
func (n *Notification) loadUser(ctx context.Context) (err error) {
427427
if n.User == nil {
428-
n.User, err = user_model.GetUserByIDCtx(ctx, n.UserID)
428+
n.User, err = user_model.GetUserByID(ctx, n.UserID)
429429
if err != nil {
430430
return fmt.Errorf("getUserByID [%d]: %w", n.UserID, err)
431431
}

models/asymkey/gpg_key_commit_verification.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ func hashAndVerifyForKeyID(sig *packet.Signature, payload string, committer *use
426426
Email: email,
427427
}
428428
if key.OwnerID != 0 {
429-
owner, err := user_model.GetUserByID(key.OwnerID)
429+
owner, err := user_model.GetUserByID(db.DefaultContext, key.OwnerID)
430430
if err == nil {
431431
signer = owner
432432
} else if !user_model.IsErrUserNotExist(err) {

models/db/index.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
"context"
88
"errors"
99
"fmt"
10+
"strconv"
11+
12+
"code.gitea.io/gitea/modules/setting"
1013
)
1114

1215
// ResourceIndex represents a resource index which could be used as issue/release and others
@@ -55,8 +58,25 @@ func SyncMaxResourceIndex(ctx context.Context, tableName string, groupID, maxInd
5558
return nil
5659
}
5760

61+
func postgresGetNextResourceIndex(ctx context.Context, tableName string, groupID int64) (int64, error) {
62+
res, err := GetEngine(ctx).Query(fmt.Sprintf("INSERT INTO %s (group_id, max_index) "+
63+
"VALUES (?,1) ON CONFLICT (group_id) DO UPDATE SET max_index = %s.max_index+1 RETURNING max_index",
64+
tableName, tableName), groupID)
65+
if err != nil {
66+
return 0, err
67+
}
68+
if len(res) == 0 {
69+
return 0, ErrGetResourceIndexFailed
70+
}
71+
return strconv.ParseInt(string(res[0]["max_index"]), 10, 64)
72+
}
73+
5874
// GetNextResourceIndex generates a resource index, it must run in the same transaction where the resource is created
5975
func GetNextResourceIndex(ctx context.Context, tableName string, groupID int64) (int64, error) {
76+
if setting.Database.UsePostgreSQL {
77+
return postgresGetNextResourceIndex(ctx, tableName, groupID)
78+
}
79+
6080
e := GetEngine(ctx)
6181

6282
// try to update the max_index to next value, and acquire the write-lock for the record

models/git/branches.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ func (protectBranch *ProtectedBranch) CanUserPush(userID int64) bool {
7373
}
7474

7575
if !protectBranch.EnableWhitelist {
76-
if user, err := user_model.GetUserByID(userID); err != nil {
76+
if user, err := user_model.GetUserByID(db.DefaultContext, userID); err != nil {
7777
log.Error("GetUserByID: %v", err)
7878
return false
79-
} else if repo, err := repo_model.GetRepositoryByID(protectBranch.RepoID); err != nil {
79+
} else if repo, err := repo_model.GetRepositoryByID(db.DefaultContext, protectBranch.RepoID); err != nil {
8080
log.Error("repo_model.GetRepositoryByID: %v", err)
8181
return false
8282
} else if writeAccess, err := access_model.HasAccessUnit(db.DefaultContext, user, repo, unit.TypeCode, perm.AccessModeWrite); err != nil {
@@ -127,13 +127,8 @@ func IsUserMergeWhitelisted(ctx context.Context, protectBranch *ProtectedBranch,
127127
}
128128

129129
// IsUserOfficialReviewer check if user is official reviewer for the branch (counts towards required approvals)
130-
func IsUserOfficialReviewer(protectBranch *ProtectedBranch, user *user_model.User) (bool, error) {
131-
return IsUserOfficialReviewerCtx(db.DefaultContext, protectBranch, user)
132-
}
133-
134-
// IsUserOfficialReviewerCtx check if user is official reviewer for the branch (counts towards required approvals)
135-
func IsUserOfficialReviewerCtx(ctx context.Context, protectBranch *ProtectedBranch, user *user_model.User) (bool, error) {
136-
repo, err := repo_model.GetRepositoryByIDCtx(ctx, protectBranch.RepoID)
130+
func IsUserOfficialReviewer(ctx context.Context, protectBranch *ProtectedBranch, user *user_model.User) (bool, error) {
131+
repo, err := repo_model.GetRepositoryByID(ctx, protectBranch.RepoID)
137132
if err != nil {
138133
return false, err
139134
}
@@ -375,7 +370,7 @@ func updateUserWhitelist(ctx context.Context, repo *repo_model.Repository, curre
375370

376371
whitelist = make([]int64, 0, len(newWhitelist))
377372
for _, userID := range newWhitelist {
378-
user, err := user_model.GetUserByIDCtx(ctx, userID)
373+
user, err := user_model.GetUserByID(ctx, userID)
379374
if err != nil {
380375
return nil, fmt.Errorf("GetUserByID [user_id: %d, repo_id: %d]: %w", userID, repo.ID, err)
381376
}
@@ -494,8 +489,8 @@ func RemoveDeletedBranchByID(repoID, id int64) (err error) {
494489

495490
// LoadUser loads the user that deleted the branch
496491
// When there's no user found it returns a user_model.NewGhostUser
497-
func (deletedBranch *DeletedBranch) LoadUser() {
498-
user, err := user_model.GetUserByID(deletedBranch.DeletedByID)
492+
func (deletedBranch *DeletedBranch) LoadUser(ctx context.Context) {
493+
user, err := user_model.GetUserByID(ctx, deletedBranch.DeletedByID)
499494
if err != nil {
500495
user = user_model.NewGhostUser()
501496
}

models/git/branches_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ func TestDeletedBranchLoadUser(t *testing.T) {
4848

4949
branch := getDeletedBranch(t, firstBranch)
5050
assert.Nil(t, branch.DeletedBy)
51-
branch.LoadUser()
51+
branch.LoadUser(db.DefaultContext)
5252
assert.NotNil(t, branch.DeletedBy)
5353
assert.Equal(t, "user1", branch.DeletedBy.Name)
5454

5555
branch = getDeletedBranch(t, secondBranch)
5656
assert.Nil(t, branch.DeletedBy)
57-
branch.LoadUser()
57+
branch.LoadUser(db.DefaultContext)
5858
assert.NotNil(t, branch.DeletedBy)
5959
assert.Equal(t, "Ghost", branch.DeletedBy.Name)
6060
}

0 commit comments

Comments
 (0)