mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-03 00:23:41 +02:00
fix broken hooks
This commit is contained in:
+26
-7
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user