Skip to content

Commit 2885c0f

Browse files
authored
Merge branch 'main' into lunny/more_refactor
2 parents bab5cd1 + 8698458 commit 2885c0f

File tree

83 files changed

+563
-533
lines changed

Some content is hidden

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

83 files changed

+563
-533
lines changed

.drone.yml

+1-1
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

+2-2
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

+2-2
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

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

+1-1
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

+2-2
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

+6-4
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/db/index.go

+20
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/commit_status.go

+18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"errors"
1010
"fmt"
1111
"net/url"
12+
"strconv"
1213
"strings"
1314
"time"
1415

@@ -49,8 +50,25 @@ func init() {
4950
db.RegisterModel(new(CommitStatusIndex))
5051
}
5152

53+
func postgresGetCommitStatusIndex(ctx context.Context, repoID int64, sha string) (int64, error) {
54+
res, err := db.GetEngine(ctx).Query("INSERT INTO `commit_status_index` (repo_id, sha, max_index) "+
55+
"VALUES (?,?,1) ON CONFLICT (repo_id, sha) DO UPDATE SET max_index = `commit_status_index`.max_index+1 RETURNING max_index",
56+
repoID, sha)
57+
if err != nil {
58+
return 0, err
59+
}
60+
if len(res) == 0 {
61+
return 0, db.ErrGetResourceIndexFailed
62+
}
63+
return strconv.ParseInt(string(res[0]["max_index"]), 10, 64)
64+
}
65+
5266
// GetNextCommitStatusIndex retried 3 times to generate a resource index
5367
func GetNextCommitStatusIndex(ctx context.Context, repoID int64, sha string) (int64, error) {
68+
if setting.Database.UsePostgreSQL {
69+
return postgresGetCommitStatusIndex(ctx, repoID, sha)
70+
}
71+
5472
e := db.GetEngine(ctx)
5573

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

models/migrations/v1_19/v234.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright 2022 The Gitea Authors. All rights reserved.
2-
// Use of this source code is governed by a MIT-style
3-
// license that can be found in the LICENSE file.
2+
// SPDX-License-Identifier: MIT
43

54
package v1_19 //nolint
65

models/migrations/v1_19/v235.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright 2022 The Gitea Authors. All rights reserved.
2-
// Use of this source code is governed by a MIT-style
3-
// license that can be found in the LICENSE file.
2+
// SPDX-License-Identifier: MIT
43

54
package v1_19 //nolint
65

models/packages/package_cleanup_rule.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright 2022 The Gitea Authors. All rights reserved.
2-
// Use of this source code is governed by a MIT-style
3-
// license that can be found in the LICENSE file.
2+
// SPDX-License-Identifier: MIT
43

54
package packages
65

modules/activitypub/client_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestActivityPubSignedPost(t *testing.T) {
3535
body, err := io.ReadAll(r.Body)
3636
assert.NoError(t, err)
3737
assert.Equal(t, expected, string(body))
38-
fmt.Fprintf(w, expected)
38+
fmt.Fprint(w, expected)
3939
}))
4040
defer srv.Close()
4141

modules/context/csrf.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1414
// License for the specific language governing permissions and limitations
1515
// under the License.
16+
// SPDX-License-Identifier: Apache-2.0
1617

1718
// a middleware that generates and validates CSRF tokens.
1819

modules/context/xsrf.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
16+
// SPDX-License-Identifier: Apache-2.0
1617

1718
package context
1819

modules/context/xsrf_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
16+
// SPDX-License-Identifier: Apache-2.0
1617

1718
package context
1819

modules/git/ref.go

+37-20
Original file line numberDiff line numberDiff line change
@@ -55,40 +55,57 @@ func (ref *Reference) Commit() (*Commit, error) {
5555

5656
// ShortName returns the short name of the reference
5757
func (ref *Reference) ShortName() string {
58-
if ref == nil {
59-
return ""
60-
}
61-
if strings.HasPrefix(ref.Name, BranchPrefix) {
62-
return strings.TrimPrefix(ref.Name, BranchPrefix)
58+
return RefName(ref.Name).ShortName()
59+
}
60+
61+
// RefGroup returns the group type of the reference
62+
func (ref *Reference) RefGroup() string {
63+
return RefName(ref.Name).RefGroup()
64+
}
65+
66+
// RefName represents a git reference name
67+
type RefName string
68+
69+
func (ref RefName) IsBranch() bool {
70+
return strings.HasPrefix(string(ref), BranchPrefix)
71+
}
72+
73+
func (ref RefName) IsTag() bool {
74+
return strings.HasPrefix(string(ref), TagPrefix)
75+
}
76+
77+
// ShortName returns the short name of the reference name
78+
func (ref RefName) ShortName() string {
79+
refName := string(ref)
80+
if strings.HasPrefix(refName, BranchPrefix) {
81+
return strings.TrimPrefix(refName, BranchPrefix)
6382
}
64-
if strings.HasPrefix(ref.Name, TagPrefix) {
65-
return strings.TrimPrefix(ref.Name, TagPrefix)
83+
if strings.HasPrefix(refName, TagPrefix) {
84+
return strings.TrimPrefix(refName, TagPrefix)
6685
}
67-
if strings.HasPrefix(ref.Name, RemotePrefix) {
68-
return strings.TrimPrefix(ref.Name, RemotePrefix)
86+
if strings.HasPrefix(refName, RemotePrefix) {
87+
return strings.TrimPrefix(refName, RemotePrefix)
6988
}
70-
if strings.HasPrefix(ref.Name, PullPrefix) && strings.IndexByte(ref.Name[pullLen:], '/') > -1 {
71-
return ref.Name[pullLen : strings.IndexByte(ref.Name[pullLen:], '/')+pullLen]
89+
if strings.HasPrefix(refName, PullPrefix) && strings.IndexByte(refName[pullLen:], '/') > -1 {
90+
return refName[pullLen : strings.IndexByte(refName[pullLen:], '/')+pullLen]
7291
}
7392

74-
return ref.Name
93+
return refName
7594
}
7695

7796
// RefGroup returns the group type of the reference
78-
func (ref *Reference) RefGroup() string {
79-
if ref == nil {
80-
return ""
81-
}
82-
if strings.HasPrefix(ref.Name, BranchPrefix) {
97+
func (ref RefName) RefGroup() string {
98+
refName := string(ref)
99+
if strings.HasPrefix(refName, BranchPrefix) {
83100
return "heads"
84101
}
85-
if strings.HasPrefix(ref.Name, TagPrefix) {
102+
if strings.HasPrefix(refName, TagPrefix) {
86103
return "tags"
87104
}
88-
if strings.HasPrefix(ref.Name, RemotePrefix) {
105+
if strings.HasPrefix(refName, RemotePrefix) {
89106
return "remotes"
90107
}
91-
if strings.HasPrefix(ref.Name, PullPrefix) && strings.IndexByte(ref.Name[pullLen:], '/') > -1 {
108+
if strings.HasPrefix(refName, PullPrefix) && strings.IndexByte(refName[pullLen:], '/') > -1 {
92109
return "pull"
93110
}
94111
return ""

modules/issue/template/unmarshal.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package template
66
import (
77
"fmt"
88
"io"
9-
"path/filepath"
9+
"path"
1010
"strconv"
1111

1212
"code.gitea.io/gitea/modules/git"
@@ -43,7 +43,7 @@ func Unmarshal(filename string, content []byte) (*api.IssueTemplate, error) {
4343

4444
// UnmarshalFromEntry parses out a valid template from the blob in entry
4545
func UnmarshalFromEntry(entry *git.TreeEntry, dir string) (*api.IssueTemplate, error) {
46-
return unmarshalFromEntry(entry, filepath.Join(dir, entry.Name()))
46+
return unmarshalFromEntry(entry, path.Join(dir, entry.Name())) // Filepaths in Git are ALWAYS '/' separated do not use filepath here
4747
}
4848

4949
// UnmarshalFromCommit parses out a valid template from the commit
@@ -108,7 +108,7 @@ func unmarshal(filename string, content []byte) (*api.IssueTemplate, error) {
108108
// It could be a valid markdown with two horizontal lines, or an invalid markdown with wrong metadata.
109109

110110
it.Content = string(content)
111-
it.Name = filepath.Base(it.FileName)
111+
it.Name = path.Base(it.FileName) // paths in Git are always '/' separated - do not use filepath!
112112
it.About, _ = util.SplitStringAtByteN(it.Content, 80)
113113
} else {
114114
it.Content = templateBody

modules/json/json.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2020 The Gitea Authors. All rights reserved.
2-
// Use of this source code is governed by a BSD-style
2+
// SPDX-License-Identifier: MIT
33

44
package json
55

modules/paginator/paginator.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright 2022 The Gitea Authors.
22
// Copyright 2015 https://github.com/unknwon. Licensed under the Apache License, Version 2.0
3+
// SPDX-License-Identifier: Apache-2.0
34

45
package paginator
56

modules/paginator/paginator_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright 2022 The Gitea Authors.
22
// Copyright 2015 https://github.com/unknwon. Licensed under the Apache License, Version 2.0
3+
// SPDX-License-Identifier: Apache-2.0
34

45
package paginator
56

modules/session/redis.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1414
// License for the specific language governing permissions and limitations
1515
// under the License.
16+
// SPDX-License-Identifier: Apache-2.0
1617

1718
package session
1819

routers/web/org/setting_packages.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright 2022 The Gitea Authors. All rights reserved.
2-
// Use of this source code is governed by a MIT-style
3-
// license that can be found in the LICENSE file.
2+
// SPDX-License-Identifier: MIT
43

54
package org
65

0 commit comments

Comments
 (0)