in core/github.py [0:0]
def parse_github_url(url: str) -> dict[str, str] | None:
"""Parses a GitHub file URL to extract owner, repo, ref (branch/tag/commit),
and file path.
Example URL: https://github.com/owner/repo/blob/main/path/to/file.txt
Args:
url: URL of file on GitHub.
Returns:
dict of URL component to value, if the URL can be parsed; otherwise None.
"""
url_object = urlparse(url)
path_parts = [part for part in url_object.path.split('/') if part]
if (
url_object.hostname != 'github.com'
or len(path_parts) < 5
or path_parts[2] != 'blob'
):
return None
[owner, repo, _, ref] = path_parts[:4]
file_path = '/'.join(path_parts[4:])
return {'owner': owner, 'repo': repo, 'ref': ref, 'path': file_path}