Skip to content

Commit 7af9982

Browse files
Improve GitHub API error handling and update auth format
Co-authored-by: Lackadaisical-Security <205846242+Lackadaisical-Security@users.noreply.github.com>
1 parent 64f642b commit 7af9982

5 files changed

Lines changed: 62 additions & 12 deletions

File tree

.github/workflows/stats-tracker.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
permissions:
1515
contents: write
16+
metadata: read
1617

1718
steps:
1819
- name: Checkout repository

REALTIME_STATS.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"timestamp": "2026-01-05T14:28:11.901823Z",
2+
"timestamp": "2026-01-05T14:32:59.155485Z",
33
"local": {
4-
"commit_count": 2,
4+
"commit_count": 3,
55
"unique_contributors": 2,
6-
"last_commit_date": "2026-01-05 14:26:06 +0000",
6+
"last_commit_date": "2026-01-05 14:30:26 +0000",
77
"last_commit_message": "Initial plan",
88
"current_branch": "copilot/fix-real-time-stats-api",
99
"tracked_files": 63,
10-
"timestamp": "2026-01-05T14:28:11.912102Z"
10+
"timestamp": "2026-01-05T14:32:59.166468Z"
1111
},
1212
"github": {}
1313
}

REALTIME_STATS.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Repository Statistics - Real-Time
22

3-
**Last Updated:** 2026-01-05T14:28:11.901823Z
3+
**Last Updated:** 2026-01-05T14:32:59.155485Z
44

55
## 📊 Current Statistics
66

@@ -9,10 +9,10 @@
99
| Metric | Value |
1010
|--------|-------|
1111
| 🌿 Current Branch | `copilot/fix-real-time-stats-api` |
12-
| 📝 Total Commits | 2 |
12+
| 📝 Total Commits | 3 |
1313
| 👥 Contributors | 2 |
1414
| 📄 Tracked Files | 63 |
15-
| 🕐 Last Commit | 2026-01-05 14:26:06 |
15+
| 🕐 Last Commit | 2026-01-05 14:30:26 |
1616
| 💬 Last Message | Initial plan |
1717

1818
---
@@ -22,7 +22,7 @@
2222
Add these to your README.md:
2323

2424
```markdown
25-
<img src="https://img.shields.io/badge/commits-2-orange?style=flat-square">
25+
<img src="https://img.shields.io/badge/commits-3-orange?style=flat-square">
2626
```
2727

2828
---

STATS_HISTORY.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,31 @@
115115
"timestamp": "2026-01-05T14:28:11.912102Z"
116116
},
117117
"github": {}
118+
},
119+
{
120+
"timestamp": "2026-01-05T14:31:28.134321Z",
121+
"local": {
122+
"commit_count": 3,
123+
"unique_contributors": 2,
124+
"last_commit_date": "2026-01-05 14:30:26 +0000",
125+
"last_commit_message": "Initial plan",
126+
"current_branch": "copilot/fix-real-time-stats-api",
127+
"tracked_files": 63,
128+
"timestamp": "2026-01-05T14:31:28.144853Z"
129+
},
130+
"github": {}
131+
},
132+
{
133+
"timestamp": "2026-01-05T14:32:59.155485Z",
134+
"local": {
135+
"commit_count": 3,
136+
"unique_contributors": 2,
137+
"last_commit_date": "2026-01-05 14:30:26 +0000",
138+
"last_commit_message": "Initial plan",
139+
"current_branch": "copilot/fix-real-time-stats-api",
140+
"tracked_files": 63,
141+
"timestamp": "2026-01-05T14:32:59.166468Z"
142+
},
143+
"github": {}
118144
}
119145
]

realtime_stats_tracker.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,41 @@ def github_api_request(self, endpoint):
3434

3535
token = self.get_github_token()
3636
if token:
37-
headers['Authorization'] = f'token {token}'
37+
headers['Authorization'] = f'Bearer {token}'
3838

3939
try:
4040
req = urllib.request.Request(url, headers=headers)
4141
with urllib.request.urlopen(req, timeout=10) as response:
4242
return json.loads(response.read().decode())
4343
except urllib.error.HTTPError as e:
44+
# Try to get detailed error message from response body
45+
error_msg = None
46+
try:
47+
error_body = e.read().decode()
48+
error_data = json.loads(error_body)
49+
error_msg = error_data.get('message', '')
50+
except:
51+
pass
52+
4453
if e.code == 403:
45-
print(f"⚠️ GitHub API rate limit reached. Set GITHUB_TOKEN env var for higher limits.")
54+
if error_msg:
55+
print(f"⚠️ GitHub API error (403): {error_msg}")
56+
if 'rate limit' in error_msg.lower():
57+
print(f"💡 Set GITHUB_TOKEN env var for higher rate limits.")
58+
elif 'credentials' in error_msg.lower() or 'token' in error_msg.lower():
59+
print(f"💡 Check that GITHUB_TOKEN has the correct permissions.")
60+
else:
61+
print(f"⚠️ GitHub API access denied (403). Set GITHUB_TOKEN env var with proper permissions.")
62+
return None
63+
elif e.code == 404:
64+
print(f"⚠️ GitHub API endpoint not found (404): {endpoint}")
65+
return None
66+
else:
67+
if error_msg:
68+
print(f"⚠️ GitHub API error {e.code}: {error_msg}")
69+
else:
70+
print(f"⚠️ GitHub API error {e.code}: {e.reason}")
4671
return None
47-
print(f"⚠️ GitHub API error {e.code}: {e.reason}")
48-
return None
4972
except Exception as e:
5073
print(f"⚠️ Error fetching from GitHub API: {e}")
5174
return None

0 commit comments

Comments
 (0)