"""Prueft ob Shared Libraries eigene Repos mit Tests haben.""" import urllib.request, json, ssl 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_BESTELLSYSTEM", "") ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE def api_get(url): req = urllib.request.Request(url) req.add_header("PRIVATE-TOKEN", TOKEN) resp = urllib.request.urlopen(req, context=ctx, timeout=30) return json.loads(resp.read().decode("utf-8")) # Alle Projekte in libraries/ Subgruppe print("=== Libraries-Subgruppe ===") url = "https://git.tech.rz.db.de/api/v4/groups/bestellsystem1/projects?per_page=100&include_subgroups=true" all_projects = api_get(url) libs = [p for p in all_projects if "/libraries/" in p["path_with_namespace"]] print(f"Projekte in libraries/: {len(libs)}") for p in libs: print(f" {p['path_with_namespace']:<60} ID={p['id']} Aktiv={p.get('last_activity_at','')[:10]}") # Fuer jede Library: CI-Pipeline pruefen (hat sie .gitlab-ci.yml?) print() print("=== CI-Pipeline und Tests pruefen ===") for p in libs: pid = p["id"] name = p["path_with_namespace"].split("/")[-1] # Pruefen ob .gitlab-ci.yml existiert try: ci_url = f"https://git.tech.rz.db.de/api/v4/projects/{pid}/repository/files/.gitlab-ci.yml?ref=master" ci_data = api_get(ci_url) has_ci = True except: has_ci = False # Pruefen ob src/test existiert try: test_url = f"https://git.tech.rz.db.de/api/v4/projects/{pid}/repository/tree?path=src/test&ref=master" test_data = api_get(test_url) has_tests = len(test_data) > 0 if test_data else False except: has_tests = False ci_str = "CI" if has_ci else "kein CI" test_str = "Tests vorhanden" if has_tests else "KEINE Tests" print(f" {name:<40} {ci_str:<8} {test_str}")