Skip to content

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

feat: support GitHub tree/<ref> URL for code repository import (#400)

yangxinxin-7755efa7621ad
diff --git a/openviking/parse/parsers/code/code.py b/openviking/parse/parsers/code/code.py
index b59fed700..ea6504bb3 100644
--- a/openviking/parse/parsers/code/code.py
+++ b/openviking/parse/parsers/code/code.py
@@ -121,13 +121,13 @@ class CodeRepositoryParser(BaseParser):
)
elif source_str.startswith(("http://", "https://", "git://", "ssh://")):
repo_url, branch, commit = self._parse_repo_source(source_str, **kwargs)
- if self._is_github_url(repo_url) and not commit:
- # Use GitHub ZIP API: single HTTPS download, no git history, much faster
+ if self._is_github_url(repo_url):
+ # Use GitHub ZIP API: supports branch names, tags, and commit SHAs
local_dir, repo_name = await self._github_zip_download(
- repo_url, branch, temp_local_dir
+ repo_url, branch or commit, temp_local_dir
)
else:
- # Non-GitHub URL or specific commit: fall back to git clone
+ # Non-GitHub URL: use git clone
repo_name = await self._git_clone(
repo_url,
temp_local_dir,
@@ -243,9 +243,18 @@ class CodeRepositoryParser(BaseParser):
if "tree" in parts:
idx = parts.index("tree")
if idx + 1 < len(parts):
- branch = unquote(parts[idx + 1])
+ ref = unquote(parts[idx + 1])
+ if self._looks_like_sha(ref):
+ commit = ref
+ else:
+ branch = ref
return branch, commit
+ @staticmethod
+ def _looks_like_sha(ref: str) -> bool:
+ """Return True if ref looks like a git commit SHA (7-40 hex chars)."""
+ return 7 <= len(ref) <= 40 and all(c in "0123456789abcdefABCDEF" for c in ref)
+
def _normalize_repo_url(self, url: str) -> str:
if url.startswith(("http://", "https://", "git://", "ssh://")):
parsed = urlparse(url)
@@ -346,7 +355,7 @@ class CodeRepositoryParser(BaseParser):
repo_slug = repo_raw[:-4] if repo_raw.endswith(".git") else repo_raw
if branch:
- zip_url = f"https://github.com/{owner}/{repo_slug}/archive/refs/heads/{branch}.zip"
+ zip_url = f"https://github.com/{owner}/{repo_slug}/archive/{branch}.zip"
else:
zip_url = f"https://github.com/{owner}/{repo_slug}/archive/HEAD.zip"
diff --git a/openviking/utils/code_hosting_utils.py b/openviking/utils/code_hosting_utils.py
index e97ddae3d..300c0f457 100644
--- a/openviking/utils/code_hosting_utils.py
+++ b/openviking/utils/code_hosting_utils.py
@@ -179,6 +179,12 @@ def is_git_repo_url(url: str) -> bool:
# Strip .git suffix from last part for counting
if path_parts and path_parts[-1].endswith(".git"):
path_parts[-1] = path_parts[-1][:-4]
- return len(path_parts) == 2
+ # owner/repo
+ if len(path_parts) == 2:
+ return True
+ # owner/repo/tree/<ref> (branch name or commit SHA)
+ if len(path_parts) == 4 and path_parts[2] == "tree":
+ return True
+ return False
return False