-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_github_api.py
More file actions
58 lines (43 loc) · 1.62 KB
/
test_github_api.py
File metadata and controls
58 lines (43 loc) · 1.62 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
#!/usr/bin/env python3
"""
Test script to verify GitHub meta API access and show current CIDR ranges.
This can be used to test connectivity before running the main script.
"""
import requests
import json
def test_github_api():
"""Test GitHub meta API and display current CIDR ranges"""
print("Testing GitHub meta API...")
print("URL: https://api.github.com/meta")
print("-" * 50)
try:
response = requests.get('https://api.github.com/meta', timeout=30)
response.raise_for_status()
data = response.json()
# Extract web and git CIDR ranges
web_cidrs = data.get('web', [])
git_cidrs = data.get('git', [])
print(f"✅ Successfully fetched GitHub CIDR ranges")
print(f"📊 Web CIDRs: {len(web_cidrs)} ranges")
print(f"📊 Git CIDRs: {len(git_cidrs)} ranges")
print()
print("🌐 Web CIDR ranges:")
for i, cidr in enumerate(web_cidrs, 1):
print(f" {i:2d}. {cidr}")
print()
print("📡 Git CIDR ranges:")
for i, cidr in enumerate(git_cidrs, 1):
print(f" {i:2d}. {cidr}")
print()
print("🔍 Full API response:")
print(json.dumps(data, indent=2))
return True
except requests.exceptions.RequestException as e:
print(f"❌ Failed to fetch GitHub CIDR ranges: {e}")
return False
except Exception as e:
print(f"❌ Unexpected error: {e}")
return False
if __name__ == '__main__':
success = test_github_api()
exit(0 if success else 1)