Refactor debug_request function in update_profile.py to utilize do_request for improved error handling and code clarity
All checks were successful
Update Profile Stats / build (push) Successful in 48s

This commit is contained in:
2026-02-27 23:36:14 +00:00
parent 60ce2c5795
commit 2f4bddb11f

View File

@@ -7,33 +7,23 @@ GITEA_URL = "https://gitea.nathan-falvey.synology.me"
USERNAME = "nathan" USERNAME = "nathan"
GITEA_TOKEN = os.getenv("GITEA_TOKEN") GITEA_TOKEN = os.getenv("GITEA_TOKEN")
def do_request(url, headers=None):
try:
response = requests.get(url, headers=headers)
response.raise_for_status() # Will raise an HTTPError for bad responses
return response.json()
except requests.exceptions.RequestException as e:
print(f"Request failed: {e}")
return None
def debug_request(): def debug_request():
headers = {"Authorization": f"token {GITEA_TOKEN}"} headers = {"Authorization": f"token {GITEA_TOKEN}"}
print(f"--- Testing Connection to: {GITEA_URL} ---") print(f"--- Testing Connection to: {GITEA_URL} ---")
try: try:
# 1. Test Version API (Public-ish) print(do_request(f"{GITEA_URL}/api/v1/version", headers=headers))
print("\n1. Testing Version API...") print(do_request(f"{GITEA_URL}/api/v1/user/repos?type=owner", headers=headers))
v_res = requests.get(f"{GITEA_URL}/api/v1/version", headers=headers)
print(f"Status: {v_res.status_code}")
print(f"Response: {v_res.text}")
# 2. Test User Repo API (Requires Token)
print("\n2. Testing User Repos API...")
r_res = requests.get(f"{GITEA_URL}/api/v1/user/repos?type=owner", headers=headers)
print(f"Status: {r_res.status_code}")
if r_res.status_code != 200:
print("❌ ERROR: API rejected the token or URL is wrong.")
print(f"Server Message: {r_res.text}")
else:
repos = r_res.json()
print(f"✅ Success! Found {len(repos)} repositories.")
# Print just the first repo to see the structure
if repos:
print(f"Example Repo Data: {repos[0]['name']} - {repos[0]['html_url']}")
except Exception: except Exception:
print("\n" + "!"*30) print("\n" + "!"*30)
print("STACK TRACE (Line Numbers):") print("STACK TRACE (Line Numbers):")