INNER CODE UNIT · Python
gh
wolfSSL/wolfssl-examples · .github/scripts/ci_triage.py:43
def gh(path, method="GET", body=None, retry=True):
url = path if path.startswith("http") else f"{API}{path}"
data = json.dumps(body).encode() if body is not None else None
req = urllib.request.Request(url, method=method, data=data)
req.add_header("Authorization", f"Bearer {TOKEN}")
req.add_header("Accept", "application/vnd.github+json")
if data:
req.add_header("Content-Type", "application/json")
attempts = 3 if retry else 1
for i in range(attempts):
try:
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
except urllib.error.HTTPError:
raise
except Exception:
if i == attempts - 1: