Merge pull request #43681 from ClickHouse/fix-GITHUB_JOB_ID

Fix pagination issue in GITHUB_JOB_ID()
This commit is contained in:
Mikhail f. Shiryaev 2022-11-25 18:16:17 +01:00 committed by GitHub
commit b70456dc08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,11 +42,13 @@ def GITHUB_JOB_ID() -> str:
if _GITHUB_JOB_ID:
return _GITHUB_JOB_ID
jobs = []
page = 1
while not _GITHUB_JOB_ID:
response = get_with_retries(
f"https://api.github.com/repos/{GITHUB_REPOSITORY}/"
f"actions/runs/{GITHUB_RUN_ID}/jobs?per_page=100"
f"actions/runs/{GITHUB_RUN_ID}/jobs?per_page=100&page={page}"
)
page += 1
data = response.json()
jobs.extend(data["jobs"])
for job in data["jobs"]:
@ -55,7 +57,10 @@ def GITHUB_JOB_ID() -> str:
_GITHUB_JOB_ID = job["id"]
_GITHUB_JOB_URL = job["html_url"]
return _GITHUB_JOB_ID
if len(jobs) == data["total_count"]:
if (
len(jobs) >= data["total_count"] # just in case of inconsistency
or len(data["jobs"]) == 0 # if we excided pages
):
_GITHUB_JOB_ID = "0"
return _GITHUB_JOB_ID