Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Borda committed Sep 14, 2023
1 parent e2510d3 commit 858d624
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions .github/scripts/find-unused-caches.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Script for filtering unused caches."""

import os
from datetime import timedelta
from typing import List
Expand All @@ -8,14 +10,22 @@


def fetch_all_caches(repository: str, token: str, per_page: int = 100, max_pages: int = 100) -> List[dict]:
"""Fetch list of al caches from a given repository.
Args:
repository: user / repo-name
token: authentication token for GH API calls
per_page: number of items per listing page
max_pages: max number of listing pages
"""
# Initialize variables for pagination
all_caches = []

for page in range(max_pages):
# Get a page of caches for the repository
url = f"https://github.com/gitapi/repos/{repository}/actions/caches?page={page + 1}&per_page={per_page}"
headers = {"Authorization": f"token {token}"}
response = requests.get(url, headers=headers).json()
response = requests.get(url, headers=headers, timeout=10).json()
print(f"fetching page... {page} with {per_page} items of expected {response.get('total_count')}")
caches = response.get("actions_caches", [])

Expand Down Expand Up @@ -47,7 +57,8 @@ def fetch_all_caches(repository: str, token: str, per_page: int = 100, max_pages
return all_caches


def main(repository: str, token: str, dalay_days: float = 7, output_file: str = "unused-cashes.txt"):
def main(repository: str, token: str, dalay_days: float = 7, output_file: str = "unused-cashes.txt") -> None:
"""Entry point."""
caches = fetch_all_caches(repository, token)

delta_days = timedelta(days=dalay_days)
Expand Down

0 comments on commit 858d624

Please sign in to comment.