Skip to content

Commit 6cb20cc

Browse files
committed
Merge remote-tracking branch 'origin/main' into refactor-html-format
2 parents 409354f + a8e7cae commit 6cb20cc

28 files changed

+940
-381
lines changed

assets/go-licenses.json

+11-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

+13-12
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0
2525
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.4.1
2626
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358
27-
github.com/ProtonMail/go-crypto v1.0.0
27+
github.com/ProtonMail/go-crypto v1.1.4
2828
github.com/PuerkitoBio/goquery v1.10.0
2929
github.com/SaveTheRbtz/zstd-seekable-format-go/pkg v0.7.3
3030
github.com/alecthomas/chroma/v2 v2.15.0
@@ -54,8 +54,8 @@ require (
5454
github.com/go-chi/cors v1.2.1
5555
github.com/go-co-op/gocron v1.37.0
5656
github.com/go-enry/go-enry/v2 v2.9.1
57-
github.com/go-git/go-billy/v5 v5.6.0
58-
github.com/go-git/go-git/v5 v5.12.0
57+
github.com/go-git/go-billy/v5 v5.6.1
58+
github.com/go-git/go-git/v5 v5.13.1
5959
github.com/go-ldap/ldap/v3 v3.4.8
6060
github.com/go-redsync/redsync/v4 v4.13.0
6161
github.com/go-sql-driver/mysql v1.8.1
@@ -106,7 +106,7 @@ require (
106106
github.com/sassoftware/go-rpmutils v0.4.0
107107
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3
108108
github.com/shurcooL/vfsgen v0.0.0-20230704071429-0000e147ea92
109-
github.com/stretchr/testify v1.9.0
109+
github.com/stretchr/testify v1.10.0
110110
github.com/syndtr/goleveldb v1.0.0
111111
github.com/tstranex/u2f v1.0.0
112112
github.com/ulikunitz/xz v0.5.12
@@ -118,14 +118,14 @@ require (
118118
github.com/yuin/goldmark v1.7.8
119119
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc
120120
github.com/yuin/goldmark-meta v1.1.0
121-
golang.org/x/crypto v0.31.0
121+
golang.org/x/crypto v0.32.0
122122
golang.org/x/image v0.21.0
123-
golang.org/x/net v0.33.0
123+
golang.org/x/net v0.34.0
124124
golang.org/x/oauth2 v0.23.0
125125
golang.org/x/sync v0.10.0
126-
golang.org/x/sys v0.28.0
126+
golang.org/x/sys v0.29.0
127127
golang.org/x/text v0.21.0
128-
golang.org/x/tools v0.26.0
128+
golang.org/x/tools v0.29.0
129129
google.golang.org/grpc v1.67.1
130130
google.golang.org/protobuf v1.35.1
131131
gopkg.in/ini.v1 v1.67.0
@@ -186,7 +186,7 @@ require (
186186
github.com/couchbase/gomemcached v0.3.2 // indirect
187187
github.com/couchbase/goutils v0.1.2 // indirect
188188
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
189-
github.com/cyphar/filepath-securejoin v0.3.4 // indirect
189+
github.com/cyphar/filepath-securejoin v0.3.6 // indirect
190190
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
191191
github.com/davidmz/go-pageant v1.0.2 // indirect
192192
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
@@ -219,7 +219,7 @@ require (
219219
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
220220
github.com/golang-sql/sqlexp v0.1.0 // indirect
221221
github.com/golang/geo v0.0.0-20230421003525-6adc56603217 // indirect
222-
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
222+
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
223223
github.com/golang/protobuf v1.5.4 // indirect
224224
github.com/golang/snappy v0.0.4 // indirect
225225
github.com/google/btree v1.1.3 // indirect
@@ -253,6 +253,7 @@ require (
253253
github.com/mitchellh/copystructure v1.2.0 // indirect
254254
github.com/mitchellh/mapstructure v1.5.0 // indirect
255255
github.com/mitchellh/reflectwalk v1.0.2 // indirect
256+
github.com/mmcloughlin/avo v0.6.0 // indirect
256257
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
257258
github.com/modern-go/reflect2 v1.0.2 // indirect
258259
github.com/mrjones/oauth v0.0.0-20190623134757-126b35219450 // indirect
@@ -264,7 +265,7 @@ require (
264265
github.com/onsi/ginkgo v1.16.5 // indirect
265266
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
266267
github.com/pierrec/lz4/v4 v4.1.21 // indirect
267-
github.com/pjbgf/sha1cd v0.3.0 // indirect
268+
github.com/pjbgf/sha1cd v0.3.1 // indirect
268269
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
269270
github.com/prometheus/client_model v0.6.1 // indirect
270271
github.com/prometheus/common v0.60.1 // indirect
@@ -304,7 +305,7 @@ require (
304305
go.uber.org/multierr v1.11.0 // indirect
305306
go.uber.org/zap v1.27.0 // indirect
306307
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
307-
golang.org/x/mod v0.21.0 // indirect
308+
golang.org/x/mod v0.22.0 // indirect
308309
golang.org/x/time v0.7.0 // indirect
309310
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect
310311
gopkg.in/warnings.v0 v0.1.2 // indirect

go.sum

+30-40
Large diffs are not rendered by default.

models/actions/run.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (run *ActionRun) GetPushEventPayload() (*api.PushPayload, error) {
154154
}
155155

156156
func (run *ActionRun) GetPullRequestEventPayload() (*api.PullRequestPayload, error) {
157-
if run.Event == webhook_module.HookEventPullRequest || run.Event == webhook_module.HookEventPullRequestSync {
157+
if run.Event.IsPullRequest() {
158158
var payload api.PullRequestPayload
159159
if err := json.Unmarshal([]byte(run.EventPayload), &payload); err != nil {
160160
return nil, err

models/repo/repo.go

+2-52
Original file line numberDiff line numberDiff line change
@@ -784,60 +784,10 @@ func GetRepositoryByName(ctx context.Context, ownerID int64, name string) (*Repo
784784
return &repo, err
785785
}
786786

787-
func parseRepositoryURL(ctx context.Context, repoURL string) (ret struct {
788-
OwnerName, RepoName, RemainingPath string
789-
},
790-
) {
791-
// possible urls for git:
792-
// https://my.domain/sub-path/<owner>/<repo>[.git]
793-
// git+ssh://[email protected]/<owner>/<repo>[.git]
794-
// ssh://[email protected]/<owner>/<repo>[.git]
795-
// [email protected]:<owner>/<repo>[.git]
796-
797-
fillPathParts := func(s string) {
798-
s = strings.TrimPrefix(s, "/")
799-
fields := strings.SplitN(s, "/", 3)
800-
if len(fields) >= 2 {
801-
ret.OwnerName = fields[0]
802-
ret.RepoName = strings.TrimSuffix(fields[1], ".git")
803-
if len(fields) == 3 {
804-
ret.RemainingPath = "/" + fields[2]
805-
}
806-
}
807-
}
808-
809-
parsed, err := giturl.ParseGitURL(repoURL)
810-
if err != nil {
811-
return ret
812-
}
813-
if parsed.URL.Scheme == "http" || parsed.URL.Scheme == "https" {
814-
if !httplib.IsCurrentGiteaSiteURL(ctx, repoURL) {
815-
return ret
816-
}
817-
fillPathParts(strings.TrimPrefix(parsed.URL.Path, setting.AppSubURL))
818-
} else if parsed.URL.Scheme == "ssh" || parsed.URL.Scheme == "git+ssh" {
819-
domainSSH := setting.SSH.Domain
820-
domainCur := httplib.GuessCurrentHostDomain(ctx)
821-
urlDomain, _, _ := net.SplitHostPort(parsed.URL.Host)
822-
urlDomain = util.IfZero(urlDomain, parsed.URL.Host)
823-
if urlDomain == "" {
824-
return ret
825-
}
826-
// check whether URL domain is the App domain
827-
domainMatches := domainSSH == urlDomain
828-
// check whether URL domain is current domain from context
829-
domainMatches = domainMatches || (domainCur != "" && domainCur == urlDomain)
830-
if domainMatches {
831-
fillPathParts(parsed.URL.Path)
832-
}
833-
}
834-
return ret
835-
}
836-
837787
// GetRepositoryByURL returns the repository by given url
838788
func GetRepositoryByURL(ctx context.Context, repoURL string) (*Repository, error) {
839-
ret := parseRepositoryURL(ctx, repoURL)
840-
if ret.OwnerName == "" {
789+
ret, err := giturl.ParseRepositoryURL(ctx, repoURL)
790+
if err != nil || ret.OwnerName == "" {
841791
return nil, fmt.Errorf("unknown or malformed repository URL")
842792
}
843793
return GetRepositoryByOwnerAndName(ctx, ret.OwnerName, ret.RepoName)

models/repo/repo_test.go

-77
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@
44
package repo
55

66
import (
7-
"context"
8-
"net/http"
9-
"net/url"
107
"testing"
118

129
"code.gitea.io/gitea/models/db"
1310
"code.gitea.io/gitea/models/unit"
1411
"code.gitea.io/gitea/models/unittest"
1512
user_model "code.gitea.io/gitea/models/user"
16-
"code.gitea.io/gitea/modules/httplib"
1713
"code.gitea.io/gitea/modules/markup"
1814
"code.gitea.io/gitea/modules/optional"
1915
"code.gitea.io/gitea/modules/setting"
@@ -132,79 +128,6 @@ func TestMetas(t *testing.T) {
132128
assert.Equal(t, ",owners,team1,", metas["teams"])
133129
}
134130

135-
func TestParseRepositoryURLPathSegments(t *testing.T) {
136-
defer test.MockVariableValue(&setting.AppURL, "https://localhost:3000")()
137-
138-
ctxURL, _ := url.Parse("https://gitea")
139-
ctxReq := &http.Request{URL: ctxURL, Header: http.Header{}}
140-
ctxReq.Host = ctxURL.Host
141-
ctxReq.Header.Add("X-Forwarded-Proto", ctxURL.Scheme)
142-
ctx := context.WithValue(context.Background(), httplib.RequestContextKey, ctxReq)
143-
cases := []struct {
144-
input string
145-
ownerName, repoName, remaining string
146-
}{
147-
{input: "/user/repo"},
148-
149-
{input: "https://localhost:3000/user/repo", ownerName: "user", repoName: "repo"},
150-
{input: "https://external:3000/user/repo"},
151-
152-
{input: "https://localhost:3000/user/repo.git/other", ownerName: "user", repoName: "repo", remaining: "/other"},
153-
154-
{input: "https://gitea/user/repo", ownerName: "user", repoName: "repo"},
155-
{input: "https://gitea:3333/user/repo"},
156-
157-
{input: "ssh://try.gitea.io:2222/user/repo", ownerName: "user", repoName: "repo"},
158-
{input: "ssh://external:2222/user/repo"},
159-
160-
{input: "git+ssh://[email protected]/user/repo.git", ownerName: "user", repoName: "repo"},
161-
{input: "git+ssh://user@external/user/repo.git"},
162-
163-
{input: "[email protected]:user/repo.git", ownerName: "user", repoName: "repo"},
164-
{input: "root@gitea:user/repo.git", ownerName: "user", repoName: "repo"},
165-
{input: "root@external:user/repo.git"},
166-
}
167-
168-
for _, c := range cases {
169-
t.Run(c.input, func(t *testing.T) {
170-
ret := parseRepositoryURL(ctx, c.input)
171-
assert.Equal(t, c.ownerName, ret.OwnerName)
172-
assert.Equal(t, c.repoName, ret.RepoName)
173-
assert.Equal(t, c.remaining, ret.RemainingPath)
174-
})
175-
}
176-
177-
t.Run("WithSubpath", func(t *testing.T) {
178-
defer test.MockVariableValue(&setting.AppURL, "https://localhost:3000/subpath")()
179-
defer test.MockVariableValue(&setting.AppSubURL, "/subpath")()
180-
cases = []struct {
181-
input string
182-
ownerName, repoName, remaining string
183-
}{
184-
{input: "https://localhost:3000/user/repo"},
185-
{input: "https://localhost:3000/subpath/user/repo.git/other", ownerName: "user", repoName: "repo", remaining: "/other"},
186-
187-
{input: "ssh://try.gitea.io:2222/user/repo", ownerName: "user", repoName: "repo"},
188-
{input: "ssh://external:2222/user/repo"},
189-
190-
{input: "git+ssh://[email protected]/user/repo.git", ownerName: "user", repoName: "repo"},
191-
{input: "git+ssh://user@external/user/repo.git"},
192-
193-
{input: "[email protected]:user/repo.git", ownerName: "user", repoName: "repo"},
194-
{input: "root@external:user/repo.git"},
195-
}
196-
197-
for _, c := range cases {
198-
t.Run(c.input, func(t *testing.T) {
199-
ret := parseRepositoryURL(ctx, c.input)
200-
assert.Equal(t, c.ownerName, ret.OwnerName)
201-
assert.Equal(t, c.repoName, ret.RepoName)
202-
assert.Equal(t, c.remaining, ret.RemainingPath)
203-
})
204-
}
205-
})
206-
}
207-
208131
func TestGetRepositoryByURL(t *testing.T) {
209132
assert.NoError(t, unittest.PrepareTestDatabase())
210133

modules/git/commit_info.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ package git
77
type CommitInfo struct {
88
Entry *TreeEntry
99
Commit *Commit
10-
SubModuleFile *CommitSubModuleFile
10+
SubmoduleFile *CommitSubmoduleFile
1111
}

modules/git/commit_info_gogit.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath
8585
} else if subModule != nil {
8686
subModuleURL = subModule.URL
8787
}
88-
subModuleFile := NewCommitSubModuleFile(subModuleURL, entry.ID.String())
89-
commitsInfo[i].SubModuleFile = subModuleFile
88+
subModuleFile := NewCommitSubmoduleFile(subModuleURL, entry.ID.String())
89+
commitsInfo[i].SubmoduleFile = subModuleFile
9090
}
9191
}
9292

modules/git/commit_info_nogogit.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath
7979
} else if subModule != nil {
8080
subModuleURL = subModule.URL
8181
}
82-
subModuleFile := NewCommitSubModuleFile(subModuleURL, entry.ID.String())
83-
commitsInfo[i].SubModuleFile = subModuleFile
82+
subModuleFile := NewCommitSubmoduleFile(subModuleURL, entry.ID.String())
83+
commitsInfo[i].SubmoduleFile = subModuleFile
8484
}
8585
}
8686

modules/git/commit_submodule.go

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
package git
55

6+
type SubmoduleWebLink struct {
7+
RepoWebLink, CommitWebLink string
8+
}
9+
610
// GetSubModules get all the submodules of current revision git tree
711
func (c *Commit) GetSubModules() (*ObjectCache[*SubModule], error) {
812
if c.submoduleCache != nil {

0 commit comments

Comments
 (0)