Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/stats-tracker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: write
metadata: read

steps:
- name: Checkout repository
Expand Down
12 changes: 6 additions & 6 deletions REALTIME_STATS.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"timestamp": "2026-01-04T23:06:02.761107Z",
"timestamp": "2026-01-05T14:37:41.805435Z",
"local": {
"commit_count": 4,
"commit_count": 5,
"unique_contributors": 2,
"last_commit_date": "2026-01-04 23:04:23 +0000",
"last_commit_message": "Remove stats files from .gitignore to enable auto-tracking workflow",
"current_branch": "copilot/fix-auto-tracking-issues",
"last_commit_date": "2026-01-05 14:36:30 +0000",
"last_commit_message": "Add caching for GitHub stats when API calls fail",
"current_branch": "copilot/fix-real-time-stats-api",
"tracked_files": 63,
"timestamp": "2026-01-04T23:06:02.771988Z"
"timestamp": "2026-01-05T14:37:41.816614Z"
},
"github": {}
}
12 changes: 6 additions & 6 deletions REALTIME_STATS.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Repository Statistics - Real-Time

**Last Updated:** 2026-01-04T23:06:02.761107Z
**Last Updated:** 2026-01-05T14:37:41.805435Z

## 📊 Current Statistics

### Local Repository

| Metric | Value |
|--------|-------|
| 🌿 Current Branch | `copilot/fix-auto-tracking-issues` |
| 📝 Total Commits | 4 |
| 🌿 Current Branch | `copilot/fix-real-time-stats-api` |
| 📝 Total Commits | 5 |
| 👥 Contributors | 2 |
| 📄 Tracked Files | 63 |
| 🕐 Last Commit | 2026-01-04 23:04:23 |
| 💬 Last Message | Remove stats files from .gitignore to enable auto-tracking workflow |
| 🕐 Last Commit | 2026-01-05 14:36:30 |
| 💬 Last Message | Add caching for GitHub stats when API calls fail |

---

Expand All @@ -22,7 +22,7 @@
Add these to your README.md:

```markdown
<img src="https://img.shields.io/badge/commits-4-orange?style=flat-square">
<img src="https://img.shields.io/badge/commits-5-orange?style=flat-square">
```

---
Expand Down
78 changes: 78 additions & 0 deletions STATS_HISTORY.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,83 @@
"timestamp": "2026-01-04T23:06:02.771988Z"
},
"github": {}
},
{
"timestamp": "2026-01-05T14:28:02.069860Z",
"local": {
"commit_count": 2,
"unique_contributors": 2,
"last_commit_date": "2026-01-05 14:26:06 +0000",
"last_commit_message": "Initial plan",
"current_branch": "copilot/fix-real-time-stats-api",
"tracked_files": 63,
"timestamp": "2026-01-05T14:28:02.080588Z"
},
"github": {}
},
{
"timestamp": "2026-01-05T14:28:11.901823Z",
"local": {
"commit_count": 2,
"unique_contributors": 2,
"last_commit_date": "2026-01-05 14:26:06 +0000",
"last_commit_message": "Initial plan",
"current_branch": "copilot/fix-real-time-stats-api",
"tracked_files": 63,
"timestamp": "2026-01-05T14:28:11.912102Z"
},
"github": {}
},
{
"timestamp": "2026-01-05T14:31:28.134321Z",
"local": {
"commit_count": 3,
"unique_contributors": 2,
"last_commit_date": "2026-01-05 14:30:26 +0000",
"last_commit_message": "Initial plan",
"current_branch": "copilot/fix-real-time-stats-api",
"tracked_files": 63,
"timestamp": "2026-01-05T14:31:28.144853Z"
},
"github": {}
},
{
"timestamp": "2026-01-05T14:32:59.155485Z",
"local": {
"commit_count": 3,
"unique_contributors": 2,
"last_commit_date": "2026-01-05 14:30:26 +0000",
"last_commit_message": "Initial plan",
"current_branch": "copilot/fix-real-time-stats-api",
"tracked_files": 63,
"timestamp": "2026-01-05T14:32:59.166468Z"
},
"github": {}
},
{
"timestamp": "2026-01-05T14:36:19.877520Z",
"local": {
"commit_count": 4,
"unique_contributors": 2,
"last_commit_date": "2026-01-05 14:33:19 +0000",
"last_commit_message": "Improve GitHub API error handling and update auth format",
"current_branch": "copilot/fix-real-time-stats-api",
"tracked_files": 63,
"timestamp": "2026-01-05T14:36:19.888287Z"
},
"github": {}
},
{
"timestamp": "2026-01-05T14:37:41.805435Z",
"local": {
"commit_count": 5,
"unique_contributors": 2,
"last_commit_date": "2026-01-05 14:36:30 +0000",
"last_commit_message": "Add caching for GitHub stats when API calls fail",
"current_branch": "copilot/fix-real-time-stats-api",
"tracked_files": 63,
"timestamp": "2026-01-05T14:37:41.816614Z"
},
"github": {}
}
]
56 changes: 51 additions & 5 deletions realtime_stats_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,41 @@ def github_api_request(self, endpoint):

token = self.get_github_token()
if token:
headers['Authorization'] = f'token {token}'
headers['Authorization'] = f'Bearer {token}'

try:
req = urllib.request.Request(url, headers=headers)
with urllib.request.urlopen(req, timeout=10) as response:
return json.loads(response.read().decode())
except urllib.error.HTTPError as e:
# Try to get detailed error message from response body
error_msg = None
try:
error_body = e.read().decode()
error_data = json.loads(error_body)
error_msg = error_data.get('message', '')
except Exception:
pass

if e.code == 403:
print(f"⚠️ GitHub API rate limit reached. Set GITHUB_TOKEN env var for higher limits.")
if error_msg:
print(f"⚠️ GitHub API error (403): {error_msg}")
if 'rate limit' in error_msg.lower():
print(f"💡 Set GITHUB_TOKEN env var for higher rate limits.")
elif 'credentials' in error_msg.lower() or 'token' in error_msg.lower():
print(f"💡 Check that GITHUB_TOKEN has the correct permissions.")
else:
print(f"⚠️ GitHub API access denied (403). Set GITHUB_TOKEN env var with proper permissions.")
return None
elif e.code == 404:
print(f"⚠️ GitHub API endpoint not found (404): {endpoint}")
return None
else:
if error_msg:
print(f"⚠️ GitHub API error {e.code}: {error_msg}")
else:
print(f"⚠️ GitHub API error {e.code}: {e.reason}")
return None
print(f"⚠️ GitHub API error {e.code}: {e.reason}")
return None
except Exception as e:
print(f"⚠️ Error fetching from GitHub API: {e}")
return None
Expand Down Expand Up @@ -151,12 +174,28 @@ def collect_stats(self):
"""Collect all statistics"""
print("🔍 Collecting repository statistics...\n")

# Try to load previous stats for fallback
previous_github_stats = {}
if self.stats_file.exists():
try:
with open(self.stats_file, 'r') as f:
previous_data = json.load(f)
previous_github_stats = previous_data.get('github', {})
except Exception:
pass

stats = {
"timestamp": datetime.now(UTC).strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
"local": self.get_local_git_stats(),
"github": self.get_github_stats()
}

# If GitHub stats are empty but we have previous stats, preserve them
if not stats["github"] and previous_github_stats:
print("ℹ️ Using cached GitHub stats from previous successful fetch")
stats["github"] = previous_github_stats
stats["github_cached"] = True

return stats

def save_stats(self, stats):
Expand Down Expand Up @@ -226,6 +265,8 @@ def display_stats(self, stats):
# GitHub stats
if stats.get("github"):
print("\n🌐 GITHUB STATISTICS:")
if stats.get("github_cached"):
print(" ℹ️ (Using cached data from previous successful fetch)")
print("-" * 80)
gh = stats["github"]
print(f" ⭐ Stars: {gh.get('stars', 'N/A')}")
Expand All @@ -251,7 +292,12 @@ def generate_stats_markdown(self, stats):
md = f"""# Repository Statistics - Real-Time

**Last Updated:** {stats['timestamp']}

"""

if stats.get("github_cached"):
md += "\n> ℹ️ **Note:** GitHub metrics below are cached from previous successful fetch (current API call failed)\n"

md += """
## 📊 Current Statistics

"""
Expand Down