-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api_usage.py
More file actions
102 lines (84 loc) · 3.47 KB
/
Copy pathtest_api_usage.py
File metadata and controls
102 lines (84 loc) · 3.47 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python3
"""Test script to measure actual API usage of show_commit_history.py"""
import sys
import os
import subprocess
# Add common_github to path
sys.path.insert(0, os.path.dirname(__file__))
from common_github import GitHubAPIClient
def main():
# Use the same token loading mechanism as GitHubAPIClient
client = GitHubAPIClient() # Will auto-load from ~/.config/github-token or ~/.config/gh/hosts.yml
if not client.has_token():
print("ERROR: No GitHub token found. Run 'gh auth login' or create ~/.config/github-token")
sys.exit(1)
# Get rate limit BEFORE
before = client.get_core_rate_limit_info()
if not before:
print("ERROR: Could not get rate limit info")
sys.exit(1)
used_before = before.get('limit', 5000) - before.get('remaining', 0)
print(f"BEFORE: remaining={before['remaining']}, used={used_before}")
# Run show_commit_history.py
print("\nRunning show_commit_history.py with debug...")
result = subprocess.run([
'python3', 'html_pages/show_commit_history.py',
'--repo-path', '/home/keivenc/dev/dynamo_ci',
'--output', '/tmp/test_commit_history.html',
'--max-commits', '5',
'--skip-gitlab-api',
'--debug' # Enable debug mode
], capture_output=True, text=True, cwd=os.path.dirname(__file__))
if result.returncode != 0:
print(f"ERROR: Script failed with code {result.returncode}")
print("STDERR:", result.stderr)
print("STDOUT:", result.stdout)
sys.exit(1)
# Print debug output if available
if result.stderr:
print("\n=== Debug output (stderr) ===")
for line in result.stderr.split('\n')[:50]: # First 50 lines
if 'REST GET' in line or 'github' in line.lower():
print(line)
print("Script completed.")
# Get rate limit AFTER
after = client.get_core_rate_limit_info()
if not after:
print("ERROR: Could not get rate limit info after")
sys.exit(1)
used_after = after.get('limit', 5000) - after.get('remaining', 0)
print(f"\nAFTER: remaining={after['remaining']}, used={used_after}")
# Calculate delta
delta = used_after - used_before
print(f"\n{'='*60}")
print(f"ACTUAL API CALLS USED: {delta}")
print(f"{'='*60}")
# Now extract statistics from the generated HTML
print("\nExtracting statistics from generated HTML...")
import re
with open('/tmp/test_commit_history.html', 'r') as f:
html = f.read()
# Extract all github.rest metrics
pattern = r'<td class="k">(github\.rest[^<]*)</td>\s*<td class="v">\s*(?:<[^>]*>)?\s*([^<\n]+)'
matches = re.findall(pattern, html)
print("\n=== All github.rest metrics ===")
reported_total = None
for metric, value in matches:
value = value.strip()
if value and not value.startswith('<'):
print(f'{metric}: {value}')
if metric == 'github.rest.calls':
try:
reported_total = int(value)
except:
pass
if reported_total is not None:
print(f"\n{'='*60}")
print(f"REPORTED TOTAL: {reported_total} API calls")
print(f"ACTUAL TOTAL: {delta} API calls")
print(f"DISCREPANCY: {delta - reported_total} API calls not accounted for!")
print(f"{'='*60}")
else:
print("Could not find github.rest.calls in HTML")
if __name__ == '__main__':
main()