transformers-triage / code /run_issues.py
ArthurZ's picture
ArthurZ HF Staff
Add triage pipeline code
cc857c8 verified
Raw History Blame Contribute Delete
1.34 kB
import json, re, subprocess, time
jobs = json.load(open('issues_jobs.json'))
done = set(int(x) for x in re.findall(r'#(\d+) ok', open('issues_run.log').read())) if __import__('os').path.exists('issues_run.log') else set()
jobs = [j for j in jobs if j['n'] not in done]
N, t0, fails = len(jobs), time.time(), []
for i, j in enumerate(jobs, 1):
cmd = ['gh', 'issue', j['op'], str(j['n']), '-R', 'huggingface/transformers']
cmd += (['-r', j['reason'], '-c', j['msg']] if j['op'] == 'close' else ['-b', j['msg']])
for attempt in range(1000):
r = subprocess.run(cmd, capture_output=True, text=True)
if r.returncode == 0 or 'too quickly' not in (r.stderr + r.stdout): break
print(f'[{i}/{N}] #{j["n"]} rate-limited, sleeping 300s (attempt {attempt+1})', flush=True); time.sleep(300)
time.sleep(4) # ponytail: fixed spacing under GitHub's content-creation limit
el = time.time() - t0
if r.returncode == 0:
print(f'[{i}/{N}] #{j["n"]} {j["op"]} ok | elapsed {el:.0f}s | eta ~{el/i*(N-i):.0f}s', flush=True)
else:
err = (r.stderr or r.stdout).strip().replace('\n', ' ')[:200]
fails.append((j['n'], err)); print(f'[{i}/{N}] #{j["n"]} FAIL: {err}', flush=True)
json.dump(fails, open('issues_fail.json', 'w'))
print(f'done ok={N-len(fails)} fails={len(fails)}', flush=True)