diff options
| -rw-r--r-- | pydis_site/apps/content/utils.py | 41 | 
1 files changed, 19 insertions, 22 deletions
| diff --git a/pydis_site/apps/content/utils.py b/pydis_site/apps/content/utils.py index 5fa6353c..8c9ad036 100644 --- a/pydis_site/apps/content/utils.py +++ b/pydis_site/apps/content/utils.py @@ -75,30 +75,27 @@ def fetch_tags() -> list[Tag]:      The entire repository is downloaded and extracted locally because      getting file content would require one request per file, and can get rate-limited.      """ -    client = github_client() - -    # Grab metadata -    metadata = client.get("/repos/python-discord/bot/contents/bot/resources") -    metadata.raise_for_status() - -    hashes = {} -    for entry in metadata.json(): -        if entry["type"] == "dir": -            # Tag group -            files = client.get(entry["url"]) -            files.raise_for_status() -            files = files.json() -        else: -            files = [entry] - -        for file in files: -            hashes[file["name"]] = file["sha"] +    with github_client() as client: +        # Grab metadata +        metadata = client.get("/repos/python-discord/bot/contents/bot/resources") +        metadata.raise_for_status() + +        hashes = {} +        for entry in metadata.json(): +            if entry["type"] == "dir": +                # Tag group +                files = client.get(entry["url"]) +                files.raise_for_status() +                files = files.json() +            else: +                files = [entry] -    # Download the files -    tar_file = client.get("/repos/python-discord/bot/tarball") -    tar_file.raise_for_status() +            for file in files: +                hashes[file["name"]] = file["sha"] -    client.close() +        # Download the files +        tar_file = client.get("/repos/python-discord/bot/tarball") +        tar_file.raise_for_status()      tags = []      with tempfile.TemporaryDirectory() as folder: | 
