Files
.profile/update_profile.py

53 lines
2.4 KiB
Python

import os
import requests
import traceback
import pprint
# --- Configuration ---
GITEA_URL = "https://gitea.nathan-falvey.synology.me"
USERNAME = "nathan"
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 do_readme_build():
pass # Placeholder for the actual README build logic
# a simple function to test the API connection and print some debug information, this will be used for debugging purposes to ensure that the API connection is working correctly and to see what data is being returned from the API calls.
def debug_request():
headers = {"Authorization": f"token {GITEA_TOKEN}"}
version_info = do_request(f"{GITEA_URL}/api/v1/version", headers=headers)
version_string = version_info.get("version", "Unknown") if version_info else "Unknown"
if version_info:
print(f"Gitea Version: {version_string}")
try:
print(do_request(f"{GITEA_URL}/api/v1/version", headers=headers))
pprint.pprint(do_request(f"{GITEA_URL}/api/v1/user/repos?type=owner", headers=headers))
repos = do_request(f"{GITEA_URL}/api/v1/users/{USERNAME}/repos?type=owner", headers=headers)
if repos is not None:
print(f"Number of repos for user '{USERNAME}': {len(repos)}")
for repo in repos:
print(f"Repo Name: {repo.get('name', 'N/A')}, Repo ID: {repo.get('id', 'N/A')}")
if repo.get("has_code", False):
print(f"Repo '{repo.get('name', 'N/A')}' has code.")
print(f"Repo '{repo.get('name', 'N/A')}' is private: {repo.get('private', 'N/A')}")
print(f"Repo '{repo.get('name', 'N/A')}' is archived: {repo.get('archived', 'N/A')}")
print(f"Repo '{repo.get('name', 'N/A')}' has language: {repo.get('language', 'N/A')}")
print(f"Repo '{repo.get('name', 'N/A')}' has size: {repo.get('size', 'N/A')} KB")
except Exception:
print("\n" + "!"*30)
print("STACK TRACE (Line Numbers):")
traceback.print_exc()
print("!"*30)
if __name__ == "__main__":
debug_request()