Get file content from repository. Args: user_access_token: User's GitHub OAuth token repo_id: Repository ID path: File path in repository ref: Git reference (branch/tag/commit, default: HEAD) Returns: Decoded file content
(
self,
user_access_token: str,
repo_id: int,
path: str,
ref: str = "HEAD",
)
| 330 | return response.json() |
| 331 | |
| 332 | async def get_file_content( |
| 333 | self, |
| 334 | user_access_token: str, |
| 335 | repo_id: int, |
| 336 | path: str, |
| 337 | ref: str = "HEAD", |
| 338 | ) -> str | None: |
| 339 | """Get file content from repository. |
| 340 | |
| 341 | Args: |
| 342 | user_access_token: User's GitHub OAuth token |
| 343 | repo_id: Repository ID |
| 344 | path: File path in repository |
| 345 | ref: Git reference (branch/tag/commit, default: HEAD) |
| 346 | |
| 347 | Returns: |
| 348 | Decoded file content as string, or None if file not found |
| 349 | """ |
| 350 | try: |
| 351 | response = httpx.get( |
| 352 | f"https://api.github.com/repositories/{repo_id}/contents/{path}?ref={ref}", |
| 353 | headers={"Authorization": f"Bearer {user_access_token}"}, |
| 354 | timeout=10.0, |
| 355 | ) |
| 356 | response.raise_for_status() |
| 357 | data = response.json() |
| 358 | |
| 359 | # GitHub returns base64 encoded content |
| 360 | import base64 |
| 361 | |
| 362 | return base64.b64decode(data["content"]).decode("utf-8") |
| 363 | except httpx.HTTPStatusError as e: |
| 364 | if e.response.status_code == 404: |
| 365 | return None |
| 366 | raise |
no outgoing calls
no test coverage detected