|
14 | 14 |
|
15 | 15 |
|
16 | 16 | def get_workflow_runs(owner, repo, token): |
17 | | - endpoint = f"https://api.github.com/repos/{owner}/{repo}/actions/runs" |
| 17 | + endpoint = f"https://api.github.com/repos/{owner}/{repo}/actions/workflows" |
18 | 18 | headers = { |
19 | 19 | "Authorization": f"Bearer {token}", |
20 | 20 | "Accept": "application/vnd.github.v3+json" |
21 | 21 | } |
22 | 22 | results = [] |
23 | 23 |
|
24 | | - with ThreadPoolExecutor(max_workers=10) as executor: |
25 | | - futures = [] |
26 | | - page = 1 |
27 | | - while True: |
28 | | - future = executor.submit(requests.get, f"{endpoint}?per_page=100&page={page}", headers=headers, timeout=10) |
29 | | - futures.append(future) |
30 | | - if 'next' in future.result().links and page <= 3: |
31 | | - logger.info("Found next page %s, fetching more results...", page) |
32 | | - page += 1 |
33 | | - else: |
34 | | - break |
35 | | - for future in futures: |
36 | | - response = future.result() |
37 | | - if response is None: |
38 | | - logger.error("Failed to get response from GitHub API") |
39 | | - elif response.status_code != 200: |
40 | | - logger.error("GitHub API returned status code %d", response.status_code) |
41 | | - else: |
42 | | - data = response.json() |
43 | | - results += data["workflow_runs"] |
| 24 | + response = requests.get(endpoint, headers=headers, timeout=10) |
| 25 | + if response.status_code != 200: |
| 26 | + logger.error("GitHub API returned status code %d", response.status_code) |
| 27 | + else: |
| 28 | + workflows = response.json()["workflows"] |
| 29 | + with ThreadPoolExecutor(max_workers=10) as executor: |
| 30 | + futures = [] |
| 31 | + for workflow in workflows: |
| 32 | + future = executor.submit(requests.get, f"{workflow['url']}/runs", headers=headers, timeout=10) |
| 33 | + futures.append(future) |
| 34 | + for future in futures: |
| 35 | + response = future.result() |
| 36 | + if response is None: |
| 37 | + logger.error("Failed to get response from GitHub API") |
| 38 | + elif response.status_code != 200: |
| 39 | + logger.error("GitHub API returned status code %d", response.status_code) |
| 40 | + else: |
| 41 | + data = response.json() |
| 42 | + results += data["workflow_runs"] |
44 | 43 |
|
45 | 44 | return results |
46 | 45 |
|
|
0 commit comments