|
1 | | -"""Unified file reading with VCS support.""" |
| 1 | +"""Unified file reading with VCS and URL support.""" |
2 | 2 |
|
3 | 3 | from pathlib import Path |
4 | 4 | from typing import Optional, Union |
5 | 5 |
|
6 | 6 | from .vcs.factory import detect_vcs_provider |
| 7 | +from .url_fetcher import is_url, fetch_url_content |
7 | 8 |
|
8 | 9 |
|
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: |
10 | 11 | """ |
11 | | - Get file content from filesystem or VCS revision. |
| 12 | + Get file content from filesystem, VCS revision, or URL. |
12 | 13 | |
13 | 14 | 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 |
16 | 17 | |
17 | 18 | Returns: |
18 | 19 | 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) |
19 | 24 | """ |
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 |
21 | 35 |
|
22 | 36 | if revision is None: |
23 | 37 | # Filesystem read (backward compatible) |
|
0 commit comments