Fetch the latest commit info from GitHub Returns: (commit_hash, commit_date, commit_message)
(
repo_owner: str, repo_name: str
)
| 6 | |
| 7 | |
| 8 | async def get_github_last_commit( |
| 9 | repo_owner: str, repo_name: str |
| 10 | ) -> Tuple[str, str, str]: |
| 11 | """ |
| 12 | Fetch the latest commit info from GitHub |
| 13 | Returns: (commit_hash, commit_date, commit_message) |
| 14 | """ |
| 15 | async with aiohttp.ClientSession() as session: |
| 16 | try: |
| 17 | # Add headers to avoid rate limiting and get fresh data |
| 18 | headers = { |
| 19 | "Accept": "application/vnd.github.v3+json", |
| 20 | "If-None-Match": "", # Ignore cache |
| 21 | "Cache-Control": "no-cache", |
| 22 | } |
| 23 | |
| 24 | # Try main branch first |
| 25 | url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/commits/main" |
| 26 | async with session.get(url, headers=headers) as response: |
| 27 | if response.status == 404: |
| 28 | url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/commits/master" |
| 29 | async with session.get(url, headers=headers) as response: |
| 30 | if response.status == 200: |
| 31 | data = await response.json() |
| 32 | |
| 33 | return ( |
| 34 | data["sha"][:7], |
| 35 | data["commit"]["author"]["date"], |
| 36 | data["commit"]["message"], |
| 37 | ) |
| 38 | elif response.status == 200: |
| 39 | data = await response.json() |
| 40 | return ( |
| 41 | data["sha"][:7], |
| 42 | data["commit"]["author"]["date"], |
| 43 | data["commit"]["message"], |
| 44 | ) |
| 45 | |
| 46 | print(f"Debug - GitHub API Status: {response.status}") # Debug print |
| 47 | |
| 48 | current_time = datetime.now(timezone.utc) |
| 49 | print(f"Debug - Fallback time: {current_time.isoformat()}") # Debug print |
| 50 | return "unknown", current_time.isoformat(), "unknown" |
| 51 | except Exception as e: |
| 52 | print(f"❌ Error fetching GitHub commit info: {e}") |
| 53 | current_time = datetime.now(timezone.utc) |
| 54 | print( |
| 55 | f"Debug - Error fallback time: {current_time.isoformat()}" |
| 56 | ) # Debug print |
| 57 | return "unknown", current_time.isoformat(), "unknown" |
| 58 | |
| 59 | |
| 60 | def get_local_commit_info() -> tuple[str, str]: |