diff options
author | 2023-08-02 05:34:25 +0200 | |
---|---|---|
committer | 2023-08-02 05:34:25 +0200 | |
commit | 6f94fd902d250b5f63edd95603fc18436ee08c47 (patch) | |
tree | 2717d463184d703751f3a03e76305dbe17f12b40 /pydis_site | |
parent | Merge pull request #1061 from python-discord/dependabot/pip/sentry-sdk-1.29.2 (diff) | |
parent | Merge branch 'main' into soft-fail-on-403-in-tags (diff) |
Merge pull request #1054 from python-discord/soft-fail-on-403-in-tags
Soft fail for upstream error on fetching tag commits
Diffstat (limited to 'pydis_site')
-rw-r--r-- | pydis_site/apps/content/utils.py | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/pydis_site/apps/content/utils.py b/pydis_site/apps/content/utils.py index 56f6283d..cfd73d67 100644 --- a/pydis_site/apps/content/utils.py +++ b/pydis_site/apps/content/utils.py @@ -1,8 +1,10 @@ import datetime import functools import json +import logging import tarfile import tempfile +from http import HTTPStatus from io import BytesIO from pathlib import Path @@ -18,6 +20,7 @@ from pydis_site import settings from .models import Commit, Tag TAG_CACHE_TTL = datetime.timedelta(hours=1) +log = logging.getLogger(__name__) def github_client(**kwargs) -> httpx.Client: @@ -144,9 +147,26 @@ def set_tag_commit(tag: Tag) -> None: # Fetch and set the commit with github_client() as client: - data = client.get("/repos/python-discord/bot/commits", params={"path": path}) - data.raise_for_status() - data = data.json()[0] + response = client.get("/repos/python-discord/bot/commits", params={"path": path}) + if ( + # We want to hop out early in three cases: + # - We got a forbidden response. (GitHub wrongfully uses this for rate limits.) + # - We got ratelimited. + response.status_code in (HTTPStatus.FORBIDDEN, HTTPStatus.TOO_MANY_REQUESTS) + # - GitHub has unicorn time again and is returning 5xx codes. + or int(response.status_code / 100) == 5 + ): # pragma: no cover + log.warning( + "Received code %d from GitHub for commit history for bot file %r", + response.status_code, path, + ) + # We hop out early because otherwise, these failures may result in the + # overall request to the tag page breaking. + return + + # This should only be permanent issues from here, such as bad requests. + response.raise_for_status() + data = response.json()[0] commit = data["commit"] author, committer = commit["author"], commit["committer"] |