Pass 3 of 3 · Deep dive of PHAROSPass 1 · OverviewPass 2 · How it works
Code Observatory / function
parse_repo_spec
codeintel.git_source.parse_repo_spec
PINNED SOURCE Source and edges from the index at this commit. An execution appears only where one was recorded.
PHAROS at 975a38dMIT license
Around this symbol
Search all symbolsLoading
| Symbol | File | Resolved by |
|---|---|---|
| _is_ip_literal | git_source.py | same file |
| _local_ref | git_source.py | same file |
| RepoRef | git_source.py | same file |
| RepoSpecError | git_source.py | same file |
| Symbol | File | Resolved by |
|---|---|---|
| job_ref | runtime.py | through an import |
| submit_repository | router.py | through an import |
| Symbol | File | Resolved by |
|---|---|---|
| git_source | git_source.py | same file |
codeintel.git_source.parse_repo_specbackend/app/codeintel/git_source.py, lines 121–180Open source
def parse_repo_spec( spec: str, *, allowed_hosts: list[str] | tuple[str, ...], allow_local: bool = False,) -> RepoRef: """Validate ``spec`` and return a :class:`RepoRef`. Accepted remote forms: ``https://github.com/owner/repo(.git)``, ``github.com/owner/repo``, and ``owner/repo`` (GitHub). Local paths are accepted only when ``allow_local`` is True (the CLI, never the API). """ if not isinstance(spec, str): raise RepoSpecError("repository must be a string") spec = spec.strip() if not spec or len(spec) > 2048: raise RepoSpecError("repository reference is empty or too long") if any(ord(c) < 0x20 or c in "\\ " for c in spec): raise RepoSpecError("repository reference contains whitespace or control characters") looks_local = spec.startswith(("/", "./", "../", "~", "file:")) if looks_local: if not allow_local: raise RepoSpecError("local repositories can only be indexed from the CLI") return _local_ref(spec) if "://" not in spec: if re.match(r"^[A-Za-z0-9-]+/[A-Za-z0-9._-]+$", spec): spec = f"https://github.com/{spec}" else: spec = f"https://{spec}" try: parts = urlsplit(spec) port = parts.port # raises ValueError for "host:junk" (e.g. "javascript:alert(1)") except ValueError as exc: raise RepoSpecError("malformed repository URL") from exc if parts.scheme != "https": raise RepoSpecError("only https:// repository URLs are accepted") if parts.username or parts.password or "@" in parts.netloc: raise RepoSpecError( "credentials in repository URLs are not accepted; configure GIT_CLONE_TOKEN instead" ) if port is not None: raise RepoSpecError("custom ports are not accepted in repository URLs") if parts.query or parts.fragment: raise RepoSpecError("repository URLs must not contain a query or fragment") host = (parts.hostname or "").lower().rstrip(".") if _is_ip_literal(host): raise RepoSpecError("IP-address hosts are not accepted") allowed = {h.lower() for h in allowed_hosts} if host not in allowed: raise RepoSpecError(f"host {host!r} is not in CODEINTEL_ALLOWED_GIT_HOSTS") segments = [s for s in parts.path.split("/") if s] if segments and segments[-1].endswith(".git"): segments[-1] = segments[-1][:-4] if len(segments) < 2 or (host == "github.com" and len(segments) != 2): raise RepoSpecError("expected a URL of the form https://host/owner/repo") for seg in segments:Shows the first 60 of 74 lines. The rest is on GitHub at this commit.
What the index recorded
- Signature
def parse_repo_spec(spec: str, *, allowed_hosts: list[str] | tuple[str, ...], allow_local: bool) -> RepoRef:- File
backend/app/codeintel/git_source.py- Lines
- 121–194
- Parser
- python-ast
- Git blob
6f88470169e4935929c5f865a974bd86da564c1a- Call sites
- 17 named, 4 resolved, 13 left unlinked
- Outside this subset
- 20 more edges reach code outside the graph shown here
