34 أسطر
941 B
Python
34 أسطر
941 B
Python
import os
|
|
from typing import Dict, Any
|
|
from helpers import get_headers, build_client
|
|
|
|
BASE_URL = os.getenv(
|
|
"GITPASHA_BASE_URL",
|
|
"https://app.gitpasha.com/api/v1"
|
|
).rstrip("/")
|
|
|
|
|
|
def api_delete_repo(repo: str) -> Dict[str, Any]:
|
|
repo = repo.strip()
|
|
username = os.getenv("GITPASHA__USERNAME", "")
|
|
|
|
if "/" not in repo:
|
|
if not username:
|
|
raise ValueError("GITPASHA__USERNAME not set in .env")
|
|
repo = f"{username}/{repo}"
|
|
|
|
with build_client() as client:
|
|
url = f"{BASE_URL}/repos/{repo}"
|
|
res = client.delete(url, headers=get_headers())
|
|
|
|
try:
|
|
response_data = res.json() if res.text else {}
|
|
except Exception:
|
|
response_data = {}
|
|
|
|
if res.status_code in (200, 202, 204):
|
|
return {"status": "deleted", **response_data}
|
|
else:
|
|
res.raise_for_status()
|
|
return response_data or {"status": "deleted"}
|