-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgithub_api.py
More file actions
33 lines (27 loc) · 1.1 KB
/
github_api.py
File metadata and controls
33 lines (27 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import requests
from datetime import datetime, timezone
def get_recent_commits(username, repo, token=None, per_page=30):
url = f"https://api.github.com/repos/{username}/{repo}/commits"
params = {"per_page": per_page}
headers = {}
if token:
headers["Authorization"] = f"token {token}"
try:
response = requests.get(url, params=params, headers=headers)
print(f"[DEBUG] Status code: {response.status_code}")
response.raise_for_status()
data = response.json()
print(f"[DEBUG] First commit payload: {data[0] if data else 'None'}")
return data
except Exception as e:
print(f"[DEBUG] Failed to fetch commits: {e}")
return []
def get_recent_commit_time(username, repo, token=None):
commits = get_recent_commits(username, repo, token=token)
print(f"[DEBUG] Fetched commits for {username}/{repo}: {commits}")
if commits:
commit_time = commits[0]["commit"]["committer"]["date"]
return datetime.strptime(commit_time, "%Y-%m-%dT%H:%M:%SZ").replace(
tzinfo=timezone.utc
)
return None