Normalized Routing

This commit is contained in:
2026-05-04 18:45:51 +02:00
parent b3b81bd7d6
commit a1bb5b74f8
2 changed files with 36 additions and 2 deletions
+10 -2
View File
@@ -123,7 +123,7 @@ func parseRepoSpec(raw string) (giteaRepoSpec, bool) {
if len(parts) < 2 {
return giteaRepoSpec{}, false
}
base := (&url.URL{Scheme: "https", Host: u.Hostname()}).String()
base := (&url.URL{Scheme: "https", Host: normalizeGiteaHTTPHost(u.Hostname())}).String()
if u.Scheme == "http" || u.Scheme == "https" {
base = (&url.URL{Scheme: u.Scheme, Host: u.Host}).String()
}
@@ -139,12 +139,20 @@ func parseRepoSpec(raw string) (giteaRepoSpec, bool) {
if len(parts) < 2 {
return giteaRepoSpec{}, false
}
base := (&url.URL{Scheme: "https", Host: hostAndPath[0]}).String()
base := (&url.URL{Scheme: "https", Host: normalizeGiteaHTTPHost(hostAndPath[0])}).String()
return giteaRepoSpec{BaseURL: strings.TrimRight(base, "/"), Owner: parts[len(parts)-2], Repo: parts[len(parts)-1]}, true
}
return giteaRepoSpec{}, false
}
func normalizeGiteaHTTPHost(host string) string {
host = strings.TrimSpace(host)
if strings.HasPrefix(host, "git-ssh.") {
return "gitea." + strings.TrimPrefix(host, "git-ssh.")
}
return host
}
func resolvePartsManifestAssetURL(spec giteaRepoSpec) (string, error) {
apiURL := fmt.Sprintf("%s/api/v1/repos/%s/%s/releases/tags/%s", strings.TrimRight(spec.BaseURL, "/"), url.PathEscape(spec.Owner), url.PathEscape(spec.Repo), url.PathEscape(partsManifestReleaseTag))
var release struct {
+26
View File
@@ -0,0 +1,26 @@
package topdata
import "testing"
func TestParseRepoSpecNormalizesWestgateSSHHostToPublicGiteaHost(t *testing.T) {
spec, ok := parseRepoSpec("ssh://git@git-ssh.westgate.pw:2222/ShadowsOverWestgate/sow-module.git")
if !ok {
t.Fatal("expected SSH remote to parse")
}
if spec.BaseURL != "https://gitea.westgate.pw" {
t.Fatalf("expected public Gitea base URL, got %q", spec.BaseURL)
}
if spec.Owner != "ShadowsOverWestgate" || spec.Repo != "sow-module" {
t.Fatalf("unexpected repo spec: %#v", spec)
}
}
func TestParseRepoSpecKeepsHTTPRemoteHost(t *testing.T) {
spec, ok := parseRepoSpec("https://example.invalid/owner/repo.git")
if !ok {
t.Fatal("expected HTTPS remote to parse")
}
if spec.BaseURL != "https://example.invalid" {
t.Fatalf("expected HTTPS base URL to be preserved, got %q", spec.BaseURL)
}
}