Back to the room

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 symbols

Loading

Calls (4)
SymbolFileResolved by
_is_ip_literalgit_source.pysame file
_local_refgit_source.pysame file
RepoRefgit_source.pysame file
RepoSpecErrorgit_source.pysame file
Called by (2)
SymbolFileResolved by
job_refruntime.pythrough an import
submit_repositoryrouter.pythrough an import
Inside (1)
SymbolFileResolved by
git_sourcegit_source.pysame 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

Read it on GitHub at this commit