Fix pagination in lambdas

This commit is contained in:
alesapin 2021-10-30 01:09:07 +03:00
parent 09eb3b8fc1
commit 00be07b9af
2 changed files with 23 additions and 6 deletions

View File

@ -53,12 +53,21 @@ def list_runners(access_token):
"Authorization": f"token {access_token}", "Authorization": f"token {access_token}",
"Accept": "application/vnd.github.v3+json", "Accept": "application/vnd.github.v3+json",
} }
response = requests.get("https://api.github.com/orgs/ClickHouse/actions/runners?per_page=100", headers=headers)
response = requests.get("https://api.github.com/orgs/ClickHouse/actions/runners", headers=headers)
response.raise_for_status() response.raise_for_status()
data = response.json() data = response.json()
print("Total runners", data['total_count']) total_runners = data['total_count']
runners = data['runners'] runners = data['runners']
total_pages = int(total_runners / 100 + 1)
print("Total pages", total_pages)
for i in range(2, total_pages + 1):
response = requests.get(f"https://api.github.com/orgs/ClickHouse/actions/runners?page={i}&per_page=100", headers=headers)
response.raise_for_status()
data = response.json()
runners += data['runners']
print("Total runners", len(runners))
result = [] result = []
for runner in runners: for runner in runners:
tags = [tag['name'] for tag in runner['labels']] tags = [tag['name'] for tag in runner['labels']]

View File

@ -49,12 +49,20 @@ def list_runners(access_token):
"Authorization": f"token {access_token}", "Authorization": f"token {access_token}",
"Accept": "application/vnd.github.v3+json", "Accept": "application/vnd.github.v3+json",
} }
response = requests.get("https://api.github.com/orgs/ClickHouse/actions/runners?per_page=100", headers=headers)
response = requests.get("https://api.github.com/orgs/ClickHouse/actions/runners", headers=headers)
response.raise_for_status() response.raise_for_status()
data = response.json() data = response.json()
print("Total runners", data['total_count']) total_runners = data['total_count']
runners = data['runners'] runners = data['runners']
total_pages = int(total_runners / 100 + 1)
for i in range(2, total_pages + 1):
response = requests.get(f"https://api.github.com/orgs/ClickHouse/actions/runners?page={i}&per_page=100", headers=headers)
response.raise_for_status()
data = response.json()
runners += data['runners']
print("Total runners", len(runners))
result = [] result = []
for runner in runners: for runner in runners:
tags = [tag['name'] for tag in runner['labels']] tags = [tag['name'] for tag in runner['labels']]