Skip to content

Commit e8bc634

Browse files
committed
feat: add URL support to file reader with proper error handling
1 parent f2db735 commit e8bc634

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

code_extractor/file_reader.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
1-
"""Unified file reading with VCS support."""
1+
"""Unified file reading with VCS and URL support."""
22

33
from pathlib import Path
44
from typing import Optional, Union
55

66
from .vcs.factory import detect_vcs_provider
7+
from .url_fetcher import is_url, fetch_url_content
78

89

9-
def get_file_content(file_path: Union[str, Path], revision: Optional[str] = None) -> str:
10+
def get_file_content(path_or_url: Union[str, Path], revision: Optional[str] = None) -> str:
1011
"""
11-
Get file content from filesystem or VCS revision.
12+
Get file content from filesystem, VCS revision, or URL.
1213
1314
Args:
14-
file_path: Path to file (string or Path object)
15-
revision: Optional VCS revision (commit, branch, tag, etc.)
15+
path_or_url: Path to file, or URL to fetch (GitHub raw, GitLab raw, direct file URL)
16+
revision: Optional VCS revision (commit, branch, tag, etc.) - not supported for URLs
1617
1718
Returns:
1819
File content as string
20+
21+
Raises:
22+
ValueError: If revision is specified with URL, or if no VCS found for path
23+
URLFetchError: For URL-related errors (network, timeout, content issues)
1924
"""
20-
path_obj = Path(file_path) if isinstance(file_path, str) else file_path
25+
path_str = str(path_or_url)
26+
27+
# Handle URL case
28+
if is_url(path_str):
29+
if revision is not None:
30+
raise ValueError("revision parameter is not applicable when path_or_url is a URL")
31+
return fetch_url_content(path_str)
32+
33+
# Handle filesystem/VCS case
34+
path_obj = Path(path_str) if isinstance(path_or_url, str) else path_or_url
2135

2236
if revision is None:
2337
# Filesystem read (backward compatible)

0 commit comments

Comments
 (0)