Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(code-hosting): recognize SSH repository hosts with userinfo (#1375)

Asish Kumar2ea71231b59d
diff --git a/openviking/parse/accessors/git_accessor.py b/openviking/parse/accessors/git_accessor.py
index a159bae0b..5de654eed 100644
--- a/openviking/parse/accessors/git_accessor.py
+++ b/openviking/parse/accessors/git_accessor.py
@@ -20,6 +20,7 @@ from urllib.parse import unquote, urlparse
from openviking.utils import is_github_url, is_gitlab_url, parse_code_hosting_url
from openviking.utils.code_hosting_utils import (
+ _domain_matches,
is_code_hosting_url,
is_git_repo_url,
validate_git_ssh_uri,
@@ -275,10 +276,7 @@ class GitAccessor(DataAccessor):
base_parts = path_parts[: git_index + 1]
config = get_openviking_config()
- if (
- parsed.netloc in config.code.github_domains + config.code.gitlab_domains
- and len(path_parts) >= 2
- ):
+ if _domain_matches(parsed, config.code.github_domains + config.code.gitlab_domains):
base_parts = path_parts[:2]
base_path = "/" + "/".join(base_parts)
return parsed._replace(path=base_path, query="", fragment="").geturl()
diff --git a/openviking/parse/parsers/code/code.py b/openviking/parse/parsers/code/code.py
index fbfa7ff4a..62c37fd55 100644
--- a/openviking/parse/parsers/code/code.py
+++ b/openviking/parse/parsers/code/code.py
@@ -38,6 +38,7 @@ from openviking.parse.parsers.constants import (
)
from openviking.parse.parsers.upload_utils import upload_directory
from openviking.utils import is_github_url, parse_code_hosting_url
+from openviking.utils.code_hosting_utils import _domain_matches
from openviking_cli.utils.config import get_openviking_config
from openviking_cli.utils.logger import get_logger
@@ -291,10 +292,7 @@ class CodeRepositoryParser(BaseParser):
base_parts = path_parts[: git_index + 1]
config = get_openviking_config()
- if (
- parsed.netloc in config.code.github_domains + config.code.gitlab_domains
- and len(path_parts) >= 2
- ):
+ if _domain_matches(parsed, config.code.github_domains + config.code.gitlab_domains):
base_parts = path_parts[:2]
base_path = "/" + "/".join(base_parts)
return parsed._replace(path=base_path, query="", fragment="").geturl()
diff --git a/openviking/utils/code_hosting_utils.py b/openviking/utils/code_hosting_utils.py
index 637018ff8..5897c203f 100644
--- a/openviking/utils/code_hosting_utils.py
+++ b/openviking/utils/code_hosting_utils.py
@@ -8,11 +8,37 @@ platforms like GitHub and GitLab.
"""
from typing import Optional
-from urllib.parse import urlparse
+from urllib.parse import ParseResult, urlparse
from openviking_cli.utils.config import get_openviking_config
+def _domain_matches(parsed: ParseResult, domains: list[str]) -> bool:
+ """Return True when parsed URL host matches configured domains.
+
+ ``urlparse().netloc`` includes optional userinfo and port values. Repository
+ clone URLs commonly use forms like ``ssh://[email protected]/org/repo.git``,
+ where the netloc is ``[email protected]`` but the actual host is
+ ``github.com``.
+ """
+ hostname = parsed.hostname
+ if not hostname:
+ return False
+
+ normalized_domains = {domain.lower() for domain in domains}
+ host = hostname.lower()
+ candidates = {host}
+
+ try:
+ port = parsed.port
+ except ValueError:
+ port = None
+ if port is not None:
+ candidates.add(f"{host}:{port}")
+
+ return any(candidate in normalized_domains for candidate in candidates)
+
+
def _extract_host(url: str) -> str:
"""Extract normalized host for supported git/code-hosting URL forms."""
if url.startswith("git@"):
@@ -44,7 +70,6 @@ def parse_code_hosting_url(url: str) -> Optional[str]:
+ config.code.code_hosting_domains
)
)
- host = _extract_host(url)
# Handle git@ SSH URLs: git@host:org/repo.git
if url.startswith("git@"):
@@ -73,7 +98,7 @@ def parse_code_hosting_url(url: str) -> Optional[str]:
# For GitHub/GitLab URLs with org/repo structure
if (
- host in config.code.github_domains + config.code.gitlab_domains
+ _domain_matches(parsed, config.code.github_domains + config.code.gitlab_domains)
and len(path_parts) >= 2
):
# Take first two parts: org/repo
@@ -140,7 +165,7 @@ def is_code_hosting_url(url: str) -> bool:
host_part = url[4:].split(":", 1)[0]
return host_part in all_domains
- return _extract_host(url) in all_domains
+ return _domain_matches(urlparse(url), all_domains)
def validate_git_ssh_uri(url: str) -> None:
@@ -186,7 +211,7 @@ def is_git_repo_url(url: str) -> bool:
)
)
parsed = urlparse(url)
- if _extract_host(url) not in all_domains:
+ if not _domain_matches(parsed, all_domains):
return False
path_parts = [p for p in parsed.path.split("/") if p]
# Strip .git suffix from last part for counting
diff --git a/tests/test_code_hosting_utils.py b/tests/test_code_hosting_utils.py
index 9f9fa14fa..7568dcc77 100644
--- a/tests/test_code_hosting_utils.py
+++ b/tests/test_code_hosting_utils.py
@@ -43,6 +43,8 @@ sys.modules["openviking.utils.code_hosting_utils"] = _module
_spec.loader.exec_module(_module)
parse_code_hosting_url = _module.parse_code_hosting_url
+is_github_url = _module.is_github_url
+is_gitlab_url = _module.is_gitlab_url
is_code_hosting_url = _module.is_code_hosting_url
is_git_repo_url = _module.is_git_repo_url
validate_git_ssh_uri = _module.validate_git_ssh_uri
@@ -81,12 +83,16 @@ def test_parse_code_hosting_url_https_dotgit():
assert parse_code_hosting_url("https://github.com/org/repo.git") == "org/repo"
-def test_parse_code_hosting_url_ssh_with_userinfo():
+def test_parse_code_hosting_url_ssh_url_with_userinfo():
assert parse_code_hosting_url("ssh://[email protected]/org/repo.git") == "org/repo"
-def test_parse_code_hosting_url_https_with_explicit_port():
- assert parse_code_hosting_url("https://github.com:443/org/repo.git") == "org/repo"
+def test_parse_code_hosting_url_gitlab_ssh_url_with_userinfo():
+ assert parse_code_hosting_url("ssh://[email protected]/group/repo.git") == "group/repo"
+
+
+def test_parse_code_hosting_url_https_with_port():
+ assert parse_code_hosting_url("https://github.com:443/org/repo") == "org/repo"
# --- validate_git_ssh_uri ---
@@ -126,14 +132,25 @@ def test_is_code_hosting_url_https():
assert is_code_hosting_url("https://github.com/org/repo") is True
-def test_is_code_hosting_url_ssh_with_userinfo():
+def test_is_code_hosting_url_ssh_url_with_userinfo():
assert is_code_hosting_url("ssh://[email protected]/org/repo.git") is True
-def test_is_code_hosting_url_https_with_explicit_port():
+def test_is_code_hosting_url_https_with_port():
assert is_code_hosting_url("https://github.com:443/org/repo") is True
+# --- is_github_url / is_gitlab_url ---
+
+
+def test_is_github_url_ssh_url_with_userinfo():
+ assert is_github_url("ssh://[email protected]/org/repo.git") is True
+
+
+def test_is_gitlab_url_ssh_url_with_userinfo():
+ assert is_gitlab_url("ssh://[email protected]/group/repo.git") is True
+
+
# --- is_git_repo_url ---
@@ -145,11 +162,11 @@ def test_is_git_repo_url_https_repo():
assert is_git_repo_url("https://github.com/org/repo") is True
-def test_is_git_repo_url_ssh_with_userinfo():
+def test_is_git_repo_url_ssh_url_with_userinfo():
assert is_git_repo_url("ssh://[email protected]/org/repo.git") is True
-def test_is_git_repo_url_https_with_explicit_port():
+def test_is_git_repo_url_https_with_port():
assert is_git_repo_url("https://github.com:443/org/repo") is True
diff --git a/tests/unit/test_accessors_git.py b/tests/unit/test_accessors_git.py
index c8f316c38..71b8dd611 100644
--- a/tests/unit/test_accessors_git.py
+++ b/tests/unit/test_accessors_git.py
@@ -3,10 +3,29 @@
"""Unit tests for GitAccessor."""
from pathlib import Path
+from types import SimpleNamespace
+from unittest.mock import patch
import pytest
from openviking.parse.accessors import GitAccessor
+from openviking.utils import code_hosting_utils
+
+
+def _mock_config():
+ return SimpleNamespace(
+ code=SimpleNamespace(
+ github_domains=["github.com", "www.github.com"],
+ gitlab_domains=["gitlab.com", "www.gitlab.com"],
+ code_hosting_domains=["github.com", "gitlab.com"],
+ )
+ )
+
+
[email protected](autouse=True)
+def _patch_config():
+ with patch.object(code_hosting_utils, "get_openviking_config", side_effect=_mock_config):
+ yield
class TestGitAccessor:
@@ -60,6 +79,13 @@ class TestGitAccessor:
"""GitAccessor should handle git:// URLs."""
assert accessor.can_handle("git://github.com/volcengine/OpenViking.git") is True
+ def test_normalize_repo_url_ssh_with_userinfo_and_ref(self, accessor: GitAccessor) -> None:
+ """GitAccessor should normalize ssh URLs with userinfo using the shared host matcher."""
+ assert (
+ accessor._normalize_repo_url("ssh://[email protected]:443/volcengine/OpenViking/tree/main")
+ == "ssh://[email protected]:443/volcengine/OpenViking"
+ )
+
@pytest.mark.parametrize(
"source",
[