aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git/url
diff options
context:
space:
mode:
Diffstat (limited to 'modules/git/url')
-rw-r--r--modules/git/url/url.go10
-rw-r--r--modules/git/url/url_test.go14
2 files changed, 13 insertions, 11 deletions
diff --git a/modules/git/url/url.go b/modules/git/url/url.go
index 1c5e8377a6..aa6fa31c5e 100644
--- a/modules/git/url/url.go
+++ b/modules/git/url/url.go
@@ -133,12 +133,13 @@ func ParseRepositoryURL(ctx context.Context, repoURL string) (*RepositoryURL, er
}
}
- if parsed.URL.Scheme == "http" || parsed.URL.Scheme == "https" {
+ switch parsed.URL.Scheme {
+ case "http", "https":
if !httplib.IsCurrentGiteaSiteURL(ctx, repoURL) {
return ret, nil
}
fillPathParts(strings.TrimPrefix(parsed.URL.Path, setting.AppSubURL))
- } else if parsed.URL.Scheme == "ssh" || parsed.URL.Scheme == "git+ssh" {
+ case "ssh", "git+ssh":
domainSSH := setting.SSH.Domain
domainCur := httplib.GuessCurrentHostDomain(ctx)
urlDomain, _, _ := net.SplitHostPort(parsed.URL.Host)
@@ -166,9 +167,10 @@ func MakeRepositoryWebLink(repoURL *RepositoryURL) string {
// now, let's guess, for example:
// * git@github.com:owner/submodule.git
// * https://github.com/example/submodule1.git
- if repoURL.GitURL.Scheme == "http" || repoURL.GitURL.Scheme == "https" {
+ switch repoURL.GitURL.Scheme {
+ case "http", "https":
return strings.TrimSuffix(repoURL.GitURL.String(), ".git")
- } else if repoURL.GitURL.Scheme == "ssh" || repoURL.GitURL.Scheme == "git+ssh" {
+ case "ssh", "git+ssh":
hostname, _, _ := net.SplitHostPort(repoURL.GitURL.Host)
hostname = util.IfZero(hostname, repoURL.GitURL.Host)
urlPath := strings.TrimSuffix(repoURL.GitURL.Path, ".git")
diff --git a/modules/git/url/url_test.go b/modules/git/url/url_test.go
index 9c020adb4d..6655c20be3 100644
--- a/modules/git/url/url_test.go
+++ b/modules/git/url/url_test.go
@@ -165,8 +165,8 @@ func TestParseGitURLs(t *testing.T) {
t.Run(kase.kase, func(t *testing.T) {
u, err := ParseGitURL(kase.kase)
assert.NoError(t, err)
- assert.EqualValues(t, kase.expected.extraMark, u.extraMark)
- assert.EqualValues(t, *kase.expected, *u)
+ assert.Equal(t, kase.expected.extraMark, u.extraMark)
+ assert.Equal(t, *kase.expected, *u)
})
}
}
@@ -179,7 +179,7 @@ func TestParseRepositoryURL(t *testing.T) {
ctxReq := &http.Request{URL: ctxURL, Header: http.Header{}}
ctxReq.Host = ctxURL.Host
ctxReq.Header.Add("X-Forwarded-Proto", ctxURL.Scheme)
- ctx := context.WithValue(context.Background(), httplib.RequestContextKey, ctxReq)
+ ctx := context.WithValue(t.Context(), httplib.RequestContextKey, ctxReq)
cases := []struct {
input string
ownerName, repoName, remaining string
@@ -249,19 +249,19 @@ func TestMakeRepositoryBaseLink(t *testing.T) {
defer test.MockVariableValue(&setting.AppURL, "https://localhost:3000/subpath")()
defer test.MockVariableValue(&setting.AppSubURL, "/subpath")()
- u, err := ParseRepositoryURL(context.Background(), "https://localhost:3000/subpath/user/repo.git")
+ u, err := ParseRepositoryURL(t.Context(), "https://localhost:3000/subpath/user/repo.git")
assert.NoError(t, err)
assert.Equal(t, "/subpath/user/repo", MakeRepositoryWebLink(u))
- u, err = ParseRepositoryURL(context.Background(), "https://github.com/owner/repo.git")
+ u, err = ParseRepositoryURL(t.Context(), "https://github.com/owner/repo.git")
assert.NoError(t, err)
assert.Equal(t, "https://github.com/owner/repo", MakeRepositoryWebLink(u))
- u, err = ParseRepositoryURL(context.Background(), "git@github.com:owner/repo.git")
+ u, err = ParseRepositoryURL(t.Context(), "git@github.com:owner/repo.git")
assert.NoError(t, err)
assert.Equal(t, "https://github.com/owner/repo", MakeRepositoryWebLink(u))
- u, err = ParseRepositoryURL(context.Background(), "git+ssh://other:123/owner/repo.git")
+ u, err = ParseRepositoryURL(t.Context(), "git+ssh://other:123/owner/repo.git")
assert.NoError(t, err)
assert.Equal(t, "https://other/owner/repo", MakeRepositoryWebLink(u))
}