From 90cf8a4761a2449a5c61106213928d7a2608cfa0 Mon Sep 17 00:00:00 2001 From: Andrei Neagu Date: Fri, 5 Apr 2024 13:29:09 +0200 Subject: [PATCH] added pagination --- .../http_interface.py | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/docker_publisher_osparc_services/http_interface.py b/src/docker_publisher_osparc_services/http_interface.py index f9076c1..6ff362b 100644 --- a/src/docker_publisher_osparc_services/http_interface.py +++ b/src/docker_publisher_osparc_services/http_interface.py @@ -14,19 +14,27 @@ async def async_client(timeout: float = 30, **kwargs) -> AsyncIterator[AsyncClie yield client -async def github_did_last_repo_run_pass( - repo_model: RepoModel, branch_hash: str -) -> bool: +async def github_did_last_repo_run_pass(repo_model, branch_hash: str) -> bool: async with async_client() as client: repo_path = repo_model.repo.split("github.com/")[1].replace(".git", "") url = f"https://api.github.com/repos/{repo_path}/actions/runs" - result = await client.get(url, params={"per_page": "10"}) - runs = result.json() + params = {"per_page": "10"} associated_run: Optional[Dict[str, Any]] = None - for run in runs["workflow_runs"]: - if run["head_commit"]["id"] == branch_hash: - associated_run = run + + while url: + result = await client.get(url, params=params) + runs = result.json() + + for run in runs["workflow_runs"]: + if run["head_commit"]["id"] == branch_hash: + associated_run = run + break + + if associated_run is not None: # Branch hash found, exit the loop break + + url = result.links.get("next", {}).get("url") + if associated_run is None: raise Exception(f"Could not find associated run to commit {branch_hash}")