File size: 1,305 Bytes
cc857c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import json, re, shlex, subprocess, time
html = open('cleanup.html').read()
data = {c['number']: c for c in json.loads(re.search(r'const DATA = (.*);\nconst KEY', html, re.S).group(1).replace('<\\/', '</'))}
toks = shlex.split(open('cleanup_close.sh').read().split('R=huggingface/transformers\n', 1)[1])
cmds, cur = [], None
for t in toks:
    if t == 'gh': cur = []; cmds.append(cur)
    else: cur.append(t)
jobs = [(int(c[2]), c[6]) for c in cmds]
V4 = data[next(n for n, c in data.items() if 'based on v4' in c['message'])]['message']
STALE = {13752, 15773, 18152}
jobs = [(n, V4 if n in STALE else m) for n, m in jobs]
N, t0, fails = len(jobs), time.time(), []
for i, (n, m) in enumerate(jobs, 1):
    r = subprocess.run(['gh', 'pr', 'close', str(n), '-R', 'huggingface/transformers', '-c', m], capture_output=True, text=True)
    el = time.time() - t0
    if r.returncode == 0:
        print(f'[{i}/{N}] #{n} 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((n, err)); print(f'[{i}/{N}] #{n} FAIL: {err}', flush=True)
        if 'rate limit' in err.lower(): time.sleep(60)
json.dump(fails, open('cleanup_fail.json', 'w'))
print(f'done ok={N-len(fails)} fails={len(fails)}', flush=True)