|
2 | 2 | Service for interacting with GitHub API with rate limiting and error handling. |
3 | 3 | """ |
4 | 4 |
|
5 | | -from typing import List, Optional, Dict, Any, AsyncIterator |
6 | | - |
| 5 | +from typing import List, Optional, Dict, Any, AsyncIterator, Callable |
| 6 | +import datetime |
7 | 7 | import asyncio |
8 | 8 | import httpx |
9 | 9 | from github import Github, GithubException |
10 | 10 | # from github.Repository import Repository as GithubRepository |
11 | 11 |
|
12 | | -from ..infrastructure.rate_limiter import RateLimiter |
13 | | -from ..infrastructure.retry_manager import RetryManager |
14 | | -from ..infrastructure.error_handler import ( |
| 12 | +# from ..infrastructure.rate_limiter import RateLimiter |
| 13 | +# from ..infrastructure.retry_manager import RetryManager |
| 14 | +from ..infrastructure import ( |
15 | 15 | handle_api_error, |
16 | 16 | RateLimitError, |
17 | 17 | RepositoryNotFoundError, |
18 | 18 | DownloadError, |
| 19 | + RateLimiter, |
| 20 | + RetryManager, |
| 21 | + CacheManager, |
| 22 | + RateLimitInfo |
19 | 23 | ) |
20 | | -from ..infrastructure.cache_manager import CacheManager |
| 24 | +# from ..infrastructure.cache_manager import CacheManager |
21 | 25 | from ..models import RepositoryInfo, GitReference, RepositoryType, GitHubFile |
22 | 26 | from ..models.constants import USER_AGENT |
23 | 27 |
|
@@ -75,19 +79,19 @@ def _on_rate_limit_update(self, rate_limit_info: RateLimitInfo) -> None: |
75 | 79 | # Configure HTTP client |
76 | 80 | headers = {"Accept": "application/vnd.github.v3+json", "User-Agent": USER_AGENT} |
77 | 81 |
|
78 | | - if auth_token: |
79 | | - headers["Authorization"] = f"token {auth_token}" |
| 82 | + if self.auth_token: |
| 83 | + headers["Authorization"] = f"token {self.auth_token}" |
80 | 84 |
|
81 | 85 | self.http_client = httpx.AsyncClient( |
82 | | - headers=headers, timeout=httpx.Timeout(timeout) |
| 86 | + headers=headers, timeout=httpx.Timeout(self.timeout) |
83 | 87 | ) |
84 | 88 |
|
85 | 89 | # Sync client for PyGithub (used only for metadata) |
86 | 90 | self.github_client = ( |
87 | 91 | Github( |
88 | | - auth_token, retry=self.retry_manager.max_retries, user_agent=USER_AGENT |
| 92 | + self.auth_token, retry=self.retry_manager.max_retries, user_agent=USER_AGENT |
89 | 93 | ) |
90 | | - if auth_token |
| 94 | + if self.auth_token |
91 | 95 | else Github(retry=self.retry_manager.max_retries, user_agent=USER_AGENT) |
92 | 96 | ) |
93 | 97 |
|
@@ -129,19 +133,19 @@ async def update_rate_limit_info(self, headers: Dict[str, str]) -> None: |
129 | 133 | # Configure HTTP client |
130 | 134 | headers = {"Accept": "application/vnd.github.v3+json", "User-Agent": USER_AGENT} |
131 | 135 |
|
132 | | - if auth_token: |
133 | | - headers["Authorization"] = f"token {auth_token}" |
| 136 | + if self.auth_token: |
| 137 | + headers["Authorization"] = f"token {self.auth_token}" |
134 | 138 |
|
135 | 139 | self.http_client = httpx.AsyncClient( |
136 | | - headers=headers, timeout=httpx.Timeout(timeout) |
| 140 | + headers=headers, timeout=httpx.Timeout(self.timeout) |
137 | 141 | ) |
138 | 142 |
|
139 | 143 | # Sync client for PyGithub (used only for metadata) |
140 | 144 | self.github_client = ( |
141 | 145 | Github( |
142 | | - auth_token, retry=self.retry_manager.max_retries, user_agent=USER_AGENT |
| 146 | + self.auth_token, retry=self.retry_manager.max_retries, user_agent=USER_AGENT |
143 | 147 | ) |
144 | | - if auth_token |
| 148 | + if self.auth_token |
145 | 149 | else Github(retry=self.retry_manager.max_retries, user_agent=USER_AGENT) |
146 | 150 | ) |
147 | 151 |
|
|
0 commit comments