"""Prueft ob das Remote-Repo Commits hat.""" import urllib.request, ssl, json secrets = {} with open("project-audit/.secrets", "r", encoding="utf-8-sig") as f: for line in f: if "=" in line and not line.startswith("#"): k, v = line.strip().split("=", 1) secrets[k.strip()] = v.strip() TOKEN = secrets.get("GITLAB_TOKEN_AUDIT", "") ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE # Pruefe Projekt url = "https://git.tech.rz.db.de/api/v4/projects/AndreKnie%2Fproject-audit" req = urllib.request.Request(url) req.add_header("PRIVATE-TOKEN", TOKEN) try: resp = urllib.request.urlopen(req, context=ctx, timeout=15) proj = json.loads(resp.read().decode("utf-8")) print(f"Projekt: {proj['path_with_namespace']}") print(f"Default Branch: {proj.get('default_branch', '?')}") print(f"Letzter Push: {proj.get('last_activity_at', '?')}") print(f"Leer: {proj.get('empty_repo', '?')}") except Exception as e: print(f"Projekt-Fehler: {e}") exit(1) # Pruefe Commits print() url2 = "https://git.tech.rz.db.de/api/v4/projects/AndreKnie%2Fproject-audit/repository/commits?per_page=5" req2 = urllib.request.Request(url2) req2.add_header("PRIVATE-TOKEN", TOKEN) try: resp2 = urllib.request.urlopen(req2, context=ctx, timeout=15) commits = json.loads(resp2.read().decode("utf-8")) print(f"Remote Commits: {len(commits)}") for c in commits: print(f" {c['short_id']} | {c['created_at'][:16]} | {c['title'][:50]}") except Exception as e: print(f"Commits-Fehler: {e}") # Pruefe Branches print() url3 = "https://git.tech.rz.db.de/api/v4/projects/AndreKnie%2Fproject-audit/repository/branches" req3 = urllib.request.Request(url3) req3.add_header("PRIVATE-TOKEN", TOKEN) try: resp3 = urllib.request.urlopen(req3, context=ctx, timeout=15) branches = json.loads(resp3.read().decode("utf-8")) print(f"Branches: {len(branches)}") for b in branches: print(f" {b['name']}: {b['commit']['short_id']} ({b['commit']['created_at'][:16]})") except Exception as e: print(f"Branches-Fehler: {e}")