Retry transient GitHub report API failures (#816)

This commit is contained in:
Glenn Jocher
2026-07-12 15:45:36 +02:00
committed by GitHub
parent 374be43206
commit b785f92b29
3 changed files with 19 additions and 12 deletions
+1 -1
View File
@@ -28,4 +28,4 @@
# ├── test_summarize_pr.py
# └── ...
__version__ = "0.2.26"
__version__ = "0.2.27"
+14 -10
View File
@@ -73,16 +73,20 @@ def github_get(path, params=None, token=None, allow_skip=False):
"X-GitHub-Api-Version": "2022-11-28",
},
)
try:
with urllib.request.urlopen(request, timeout=60) as response:
return json.loads(response.read())
except urllib.error.HTTPError as e:
body = e.read().decode(errors="ignore").lower()
rate_limited = e.code == 403 and (e.headers.get("X-RateLimit-Remaining") == "0" or "rate limit" in body)
if allow_skip and e.code in {403, 404} and not rate_limited:
print(f"Skipping {path}: {e.code}")
return None
raise
for attempt in range(3):
try:
with urllib.request.urlopen(request, timeout=60) as response:
return json.loads(response.read())
except urllib.error.HTTPError as e:
if e.code in {500, 502, 503, 504} and attempt < 2:
time.sleep(2**attempt)
continue
body = e.read().decode(errors="ignore").lower()
rate_limited = e.code == 403 and (e.headers.get("X-RateLimit-Remaining") == "0" or "rate limit" in body)
if allow_skip and e.code in {403, 404} and not rate_limited:
print(f"Skipping {path}: {e.code}")
return None
raise
def paginate(path, params=None, key=None, max_pages=100, token=None, allow_skip=False):
+4 -1
View File
@@ -67,13 +67,16 @@ def test_github_get_fetches_json(monkeypatch):
def fake_urlopen(request, timeout):
requests.append((request.full_url, timeout, request.headers["Authorization"]))
if len(requests) == 1:
raise urllib.error.HTTPError("url", 504, "Gateway Timeout", {}, None)
return Response()
monkeypatch.setenv("GH_TOKEN", "token")
monkeypatch.setattr(failed_scheduled_actions.urllib.request, "urlopen", fake_urlopen)
monkeypatch.setattr(failed_scheduled_actions.time, "sleep", lambda _: None)
assert failed_scheduled_actions.github_get("/repos/ultralytics/actions", {"page": 1}) == {"ok": True}
assert requests == [("https://api.github.com/repos/ultralytics/actions?page=1", 60, "Bearer token")]
assert requests == [("https://api.github.com/repos/ultralytics/actions?page=1", 60, "Bearer token")] * 2
def test_github_get_skips_allowed_repo_errors(monkeypatch, capsys):