Skip to content

Commit

Permalink
gitmp
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
kuba-moo committed Jul 23, 2024
1 parent 83ce7f7 commit a629531
Showing 1 changed file with 41 additions and 31 deletions.
72 changes: 41 additions & 31 deletions contest/remote/gh.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ def get(url, token):
return requests.get(url, headers=headers)


def link(cbarg, config):
def link(runid, config):
return "https://github.com/" + \
config.get('ci', 'owner') + "/" + \
config.get('ci', 'repo') + "/" + \
"actions/runs/" + str(cbarg.prev_runid)
"actions/runs/" + str(runid)


def gh_namify(name):
Expand All @@ -64,36 +64,22 @@ def gh_namify(name):
return namify(name)


def get_results(config, cbarg, prev_run, page=1):
token = config.get('gh', 'token')
repo_url = f"https://api.github.com/repos/{config.get('ci', 'owner')}/{config.get('ci', 'repo')}"
ref = config.get('ci', 'runs_ref')

resp = get(repo_url + f'/actions/runs?page={page}', token)
runs = resp.json()
found = None
for run in runs.get('workflow_runs'):
if ref in [r['ref'] for r in run['referenced_workflows']]:
if found is None or found["id"] < run["id"]:
found = run
if found is None:
if page < 10:
return get_results(config, cbarg, prev_run, page=(page + 1))
print(f"Run not found, tried all {page} pages!")
return None
if prev_run == found["id"]:
print("Found old run:", prev_run)
return None
cbarg.prev_runid = found["id"]

resp = get(repo_url + f'/actions/runs/{found["id"]}/jobs', token)
def get_jobs_page(config, repo_url, found, token, page=1, res=None):
resp = get(repo_url + f'/actions/runs/{found["id"]}/jobs?page={page}', token)
jobs = resp.json()

if 'jobs' not in jobs:
print("bad jobs")
print(jobs)
print("bad jobs", jobs)
return None

if len(jobs['jobs']) == 0:
if page == 1:
print("short jobs", jobs)
return res
# Must be page 1, init res to empty array
if res is None:
res = []

decoder = {
'success': 0,
'skipped': 1,
Expand All @@ -111,8 +97,7 @@ def get_results(config, cbarg, prev_run, page=1):
5: 'fail',
}

url = link(cbarg, config)
res = []
url = link(found["id"], config)
for job in jobs["jobs"]:
if job["conclusion"] is None:
print("Still running, waiting for job:", job["name"])
Expand All @@ -133,7 +118,32 @@ def get_results(config, cbarg, prev_run, page=1):
'result': result, 'link': test_link})
if not res:
print(f"Still waiting, {len(jobs['jobs'])} jobs skipped")
return res
return get_jobs_page(config, repo_url, found, token, page=(page + 1), res=res)


def get_results(config, cbarg, prev_run, page=1):
token = config.get('gh', 'token')
repo_url = f"https://api.github.com/repos/{config.get('ci', 'owner')}/{config.get('ci', 'repo')}"
ref = config.get('ci', 'runs_ref')

resp = get(repo_url + f'/actions/runs?page={page}', token)
runs = resp.json()
found = None
for run in runs.get('workflow_runs'):
if ref in [r['ref'] for r in run['referenced_workflows']]:
if found is None or found["id"] < run["id"]:
found = run
if found is None:
if page < 10:
return get_results(config, cbarg, prev_run, page=(page + 1))
print(f"Run not found, tried all {page} pages!")
return None
if prev_run == found["id"]:
print("Found old run:", prev_run)
return None
cbarg.prev_runid = found["id"]

return get_jobs_page(config, repo_url, found, token)


def test_run(binfo, rinfo, cbarg, config, start):
Expand Down Expand Up @@ -175,7 +185,7 @@ def test_run(binfo, rinfo, cbarg, config, start):

url = config.get('gh', 'link')
if hasattr(cbarg, "prev_runid") and cbarg.prev_runid != prev_runid:
url = link(cbarg, config)
url = link(cbarg.prev_runid, config)

return [{'test': config.get('executor', 'test'),
'group': config.get('executor', 'group'),
Expand Down

0 comments on commit a629531

Please sign in to comment.