fix broken hooks

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧
2026-04-02 20:00:58 -04:00
parent ae8a64cd74
commit 37768f16aa
53 changed files with 270 additions and 175 deletions
+26 -7
View File
@@ -8,6 +8,7 @@ import (
"fmt"
"net"
stdurl "net/url"
"strconv"
"strings"
"code.gitea.io/gitea/modules/httplib"
@@ -102,6 +103,7 @@ type RepositoryURL struct {
// if the URL belongs to current Gitea instance, then the below fields have values
OwnerName string
GroupID int64
RepoName string
RemainingPath string
}
@@ -121,16 +123,25 @@ func ParseRepositoryURL(ctx context.Context, repoURL string) (*RepositoryURL, er
ret := &RepositoryURL{}
ret.GitURL = parsed
fillPathParts := func(s string) {
fillPathParts := func(s string) error {
s = strings.TrimPrefix(s, "/")
fields := strings.SplitN(s, "/", 3)
fields := strings.SplitN(s, "/", 4)
var pathErr error
if len(fields) >= 2 {
ret.OwnerName = fields[0]
ret.RepoName = strings.TrimSuffix(fields[1], ".git")
if len(fields) == 3 {
if len(fields) >= 3 {
ret.GroupID, pathErr = strconv.ParseInt(fields[1], 10, 64)
if pathErr != nil {
return pathErr
}
ret.RepoName = strings.TrimSuffix(fields[2], ".git")
ret.RemainingPath = "/" + fields[3]
} else {
ret.RepoName = strings.TrimSuffix(fields[1], ".git")
ret.RemainingPath = "/" + fields[2]
}
}
return nil
}
switch parsed.URL.Scheme {
@@ -138,7 +149,9 @@ func ParseRepositoryURL(ctx context.Context, repoURL string) (*RepositoryURL, er
if !httplib.IsCurrentGiteaSiteURL(ctx, repoURL) {
return ret, nil
}
fillPathParts(strings.TrimPrefix(parsed.URL.Path, setting.AppSubURL))
if err = fillPathParts(strings.TrimPrefix(parsed.URL.Path, setting.AppSubURL)); err != nil {
return nil, err
}
case "ssh", "git+ssh":
domainSSH := setting.SSH.Domain
domainCur := httplib.GuessCurrentHostDomain(ctx)
@@ -152,7 +165,9 @@ func ParseRepositoryURL(ctx context.Context, repoURL string) (*RepositoryURL, er
// check whether URL domain is current domain from context
domainMatches = domainMatches || (domainCur != "" && domainCur == urlDomain)
if domainMatches {
fillPathParts(parsed.URL.Path)
if err = fillPathParts(parsed.URL.Path); err != nil {
return nil, err
}
}
}
return ret, nil
@@ -161,7 +176,11 @@ func ParseRepositoryURL(ctx context.Context, repoURL string) (*RepositoryURL, er
// MakeRepositoryWebLink generates a web link (http/https) for a git repository (by guessing sometimes)
func MakeRepositoryWebLink(repoURL *RepositoryURL) string {
if repoURL.OwnerName != "" {
return setting.AppSubURL + "/" + repoURL.OwnerName + "/" + repoURL.RepoName
var groupSegment string
if repoURL.GroupID > 0 {
groupSegment = strconv.FormatInt(repoURL.GroupID, 10) + "/"
}
return setting.AppSubURL + "/" + repoURL.OwnerName + "/" + groupSegment + repoURL.RepoName
}
// now, let's guess, for example: